@@ -62,6 +62,77 @@ The first time it's used, Web3.py will create the ``ens`` instance using
62
62
w3.ens.address(' ethereum.eth' )
63
63
64
64
65
+ .. py :attribute :: ens.strict_bytes_type_checking
66
+
67
+ The ``ENS `` instance has a ``strict_bytes_type_checking `` flag that toggles the flag
68
+ with the same name on the ``Web3 `` instance attached to the ``ENS `` instance.
69
+ You may disable the stricter bytes type checking that is loaded by default using
70
+ this flag. For more examples, see :ref: `disable-strict-byte-check `
71
+
72
+ If instantiating a standalone ENS instance using ``ENS.from_web3() ``, the ENS
73
+ instance will inherit the value of the flag on the Web3 instance at time of
74
+ instantiation.
75
+
76
+ .. doctest ::
77
+
78
+ >>> from web3 import Web3, EthereumTesterProvider
79
+ >>> from ens import ENS
80
+ >>> w3 = Web3(EthereumTesterProvider())
81
+
82
+ >>> assert w3.strict_bytes_type_checking # assert strict by default
83
+ >>> w3.is_encodable(' bytes2' , b ' 1' )
84
+ False
85
+
86
+ >>> w3.strict_bytes_type_checking = False
87
+ >>> w3.is_encodable(' bytes2' , b ' 1' ) # zero-padded, so encoded to: b'1\x00'
88
+ True
89
+
90
+ >>> ns = ENS .from_web3(w3)
91
+ >>> # assert inherited from w3 at time of instantiation via ENS.from_web3()
92
+ >>> assert ns.strict_bytes_type_checking is False
93
+ >>> ns.w3.is_encodable(' bytes2' , b ' 1' )
94
+ True
95
+
96
+ >>> # assert these are now separate instances
97
+ >>> ns.strict_bytes_type_checking = True
98
+ >>> ns.w3.is_encodable(' bytes2' , b ' 1' )
99
+ False
100
+
101
+ >>> # assert w3 flag value remains
102
+ >>> assert w3.strict_bytes_type_checking is False
103
+ >>> w3.is_encodable(' bytes2' , b ' 1' )
104
+ True
105
+
106
+ However, if accessing the ``ENS `` class via the ``Web3 `` instance as a module
107
+ (``w3.ens ``), since all modules use the same ``Web3 `` object reference
108
+ under the the hood (the parent ``w3 `` object), changing the
109
+ ``strict_bytes_type_checking `` flag value on ``w3 `` also changes the flag state
110
+ for ``w3.ens.w3 `` and all modules.
111
+
112
+ .. doctest ::
113
+
114
+ >>> from web3 import Web3, EthereumTesterProvider
115
+ >>> w3 = Web3(EthereumTesterProvider())
116
+
117
+ >>> assert w3.strict_bytes_type_checking # assert strict by default
118
+ >>> w3.is_encodable(' bytes2' , b ' 1' )
119
+ False
120
+
121
+ >>> w3.strict_bytes_type_checking = False
122
+ >>> w3.is_encodable(' bytes2' , b ' 1' ) # zero-padded, so encoded to: b'1\x00'
123
+ True
124
+
125
+ >>> assert w3 == w3.ens.w3 # assert same object
126
+ >>> assert not w3.ens.w3.strict_bytes_type_checking
127
+ >>> w3.ens.w3.is_encodable(' bytes2' , b ' 1' )
128
+ True
129
+
130
+ >>> # sanity check on eth module as well
131
+ >>> assert not w3.eth.w3.strict_bytes_type_checking
132
+ >>> w3.eth.w3.is_encodable(' bytes2' , b ' 1' )
133
+ True
134
+
135
+
65
136
Usage
66
137
-----
67
138
0 commit comments