Skip to content

Commit 3bb9369

Browse files
committed
Add a doc section on enable_strict_bytes_type_checking
1 parent 9cf57a4 commit 3bb9369

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

docs/contracts.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ The following values will raise an error by default:
545545
- String is not valid hex
546546

547547
However, you may want to be stricter with acceptable values for bytes types.
548-
For this you can use the ``enable_strict_bytes_type_checking`` method,
548+
For this you can use the :meth:`w3.enable_strict_bytes_type_checking()` method,
549549
which is available on the web3 instance. A web3 instance which has had this method
550550
invoked will enforce a stricter set of rules on which values are accepted.
551551

docs/overview.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,38 @@ Cryptographic Hashing
341341
>>> Web3.soliditySha3(['address'], ["ethereumfoundation.eth"])
342342
HexBytes("0x913c99ea930c78868f1535d34cd705ab85929b2eaaf70fcd09677ecd6e5d75e9")
343343
344+
Check Encodability
345+
~~~~~~~~~~~~~~~~~~~~
346+
347+
.. py:method:: w3.is_encodable(_type, value)
348+
349+
Returns ``True`` if a value can be encoded as the given type. Otherwise returns ``False``.
350+
351+
.. code-block:: python
352+
353+
>>> from web3.auto.gethdev import w3
354+
>>> w3.is_encodable('bytes2', b'12')
355+
True
356+
>>> w3.is_encodable('bytes2', b'1')
357+
True
358+
>>> w3.is_encodable('bytes2', '0x1234')
359+
True
360+
>>> w3.is_encodable('bytes2', b'123')
361+
False
362+
363+
.. py:method:: w3.enable_strict_bytes_type_checking()
364+
365+
Enables stricter bytes type checking. For more examples see :ref:`enable-strict-byte-check`
366+
367+
.. doctest::
368+
369+
>>> from web3.auto.gethdev import w3
370+
>>> w3.enable_strict_bytes_type_checking()
371+
>>> w3.is_encodable('bytes2', b'12')
372+
True
373+
>>> w3.is_encodable('bytes2', b'1')
374+
False
375+
344376
Modules
345377
-------
346378

0 commit comments

Comments
 (0)