File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -545,7 +545,7 @@ The following values will raise an error by default:
545545 - String is not valid hex
546546
547547However, 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,
549549which is available on the web3 instance. A web3 instance which has had this method
550550invoked will enforce a stricter set of rules on which values are accepted.
551551
Original file line number Diff line number Diff 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+
344376Modules
345377-------
346378
You can’t perform that action at this time.
0 commit comments