@@ -147,6 +147,9 @@ def _denormalize(self, val: ABIType) -> int:
147147 def __eq__ (self , other : object ) -> bool :
148148 return isinstance (other , UInt ) and self ._bits == other ._bits
149149
150+ def __hash__ (self ) -> int :
151+ return hash ((type (self ), self ._bits ))
152+
150153
151154class Int (Type ):
152155 """Corresponds to the Solidity ``int<bits>`` type."""
@@ -183,6 +186,9 @@ def _denormalize(self, val: ABIType) -> int:
183186 def __eq__ (self , other : object ) -> bool :
184187 return isinstance (other , Int ) and self ._bits == other ._bits
185188
189+ def __hash__ (self ) -> int :
190+ return hash ((type (self ), self ._bits ))
191+
186192
187193class Bytes (Type ):
188194 """Corresponds to the Solidity ``bytes<size>`` type."""
@@ -199,8 +205,7 @@ def canonical_form(self) -> str:
199205 def _check_val (self , val : Any ) -> bytes :
200206 if not isinstance (val , bytes ):
201207 raise TypeError (
202- f"`{ self .canonical_form } ` must correspond to a bytestring, "
203- f"got { type (val ).__name__ } "
208+ f"`{ self .canonical_form } ` must correspond to a bytestring, got { type (val ).__name__ } "
204209 )
205210 if self ._size is not None and len (val ) != self ._size :
206211 raise ValueError (f"Expected { self ._size } bytes, got { len (val )} " )
@@ -236,6 +241,9 @@ def decode_from_topic(self, val: bytes) -> None | bytes:
236241 def __eq__ (self , other : object ) -> bool :
237242 return isinstance (other , Bytes ) and self ._size == other ._size
238243
244+ def __hash__ (self ) -> int :
245+ return hash ((type (self ), self ._size ))
246+
239247
240248class AddressType (Type ):
241249 """
@@ -250,8 +258,7 @@ def canonical_form(self) -> str:
250258 def _normalize (self , val : Any ) -> str :
251259 if not isinstance (val , Address ):
252260 raise TypeError (
253- f"`address` must correspond to an `Address`-type value, "
254- f"got { type (val ).__name__ } "
261+ f"`address` must correspond to an `Address`-type value, got { type (val ).__name__ } "
255262 )
256263 return val .checksum
257264
@@ -263,6 +270,9 @@ def _denormalize(self, val: ABIType) -> Address:
263270 def __eq__ (self , other : object ) -> bool :
264271 return isinstance (other , AddressType )
265272
273+ def __hash__ (self ) -> int :
274+ return hash (type (self ))
275+
266276
267277class String (Type ):
268278 """Corresponds to the Solidity ``string`` type."""
@@ -299,6 +309,9 @@ def decode_from_topic(self, _val: bytes) -> None:
299309 def __eq__ (self , other : object ) -> bool :
300310 return isinstance (other , String )
301311
312+ def __hash__ (self ) -> int :
313+ return hash (type (self ))
314+
302315
303316class Bool (Type ):
304317 """Corresponds to the Solidity ``bool`` type."""
@@ -323,6 +336,9 @@ def _denormalize(self, val: ABIType) -> bool:
323336 def __eq__ (self , other : object ) -> bool :
324337 return isinstance (other , Bool )
325338
339+ def __hash__ (self ) -> int :
340+ return hash (type (self ))
341+
326342
327343class Array (Type ):
328344 """Corresponds to the Solidity array (``[<size>]``) type."""
@@ -366,6 +382,9 @@ def __eq__(self, other: object) -> bool:
366382 and self ._size == other ._size
367383 )
368384
385+ def __hash__ (self ) -> int :
386+ return hash ((type (self ), self ._element_type , self ._size ))
387+
369388
370389class Struct (Type ):
371390 """Corresponds to the Solidity struct type."""
@@ -426,6 +445,9 @@ def __eq__(self, other: object) -> bool:
426445 and list (self ._fields ) == list (other ._fields )
427446 )
428447
448+ def __hash__ (self ) -> int :
449+ return hash ((type (self ), tuple (self ._fields .items ())))
450+
429451
430452_UINT_RE = re .compile (r"uint(\d+)" )
431453_INT_RE = re .compile (r"int(\d+)" )
0 commit comments