File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 16
16
Set ,
17
17
_SpecialForm ,
18
18
)
19
-
20
- # import typing as ty
19
+ import attrs .exceptions
21
20
22
21
try :
23
22
from typing import Protocol
@@ -73,6 +72,7 @@ def hash_object(obj: object) -> Hash:
73
72
try :
74
73
return hash_single (obj , Cache ({}))
75
74
except Exception as e :
75
+ hash_single (obj , Cache ({}))
76
76
raise UnhashableError (f"Cannot hash object { obj !r} " ) from e
77
77
78
78
@@ -103,7 +103,16 @@ def __bytes_repr__(self, cache: Cache) -> Iterator[bytes]:
103
103
def bytes_repr (obj : object , cache : Cache ) -> Iterator [bytes ]:
104
104
cls = obj .__class__
105
105
yield f"{ cls .__module__ } .{ cls .__name__ } :{{" .encode ()
106
- yield from bytes_repr_mapping_contents (obj .__dict__ , cache )
106
+ try :
107
+ dct = obj .__dict__
108
+ except AttributeError as e :
109
+ # Attrs creates slots classes by default, so we add this here to handle those
110
+ # cases
111
+ try :
112
+ dct = attrs .asdict (obj , recurse = False ) # type: ignore
113
+ except attrs .exceptions .NotAnAttrsClassError :
114
+ raise TypeError (f"Cannot hash { obj } as it is a slots class" ) from e
115
+ yield from bytes_repr_mapping_contents (dct , cache )
107
116
yield b"}"
108
117
109
118
You can’t perform that action at this time.
0 commit comments