(Jan-16-2020, 09:42 AM)hobbitdur Wrote: And my class Building is Hashable.No, it's not hashable*, because one of the fields is dict, which is mutable and not hashable, thus the whole Building dataclass is not hashable*.
as it says in the docs:
Quote:hashable
An object is hashable if it has a hash value which never changes during its lifetime (it needs a __hash__() method), and can be compared to other objects (it needs an __eq__() or __cmp__() method). Hashable objects which compare equal must have the same hash value.
Hashability makes an object usable as a dictionary key and a set member, because these data structures use the hash value internally.
All of Python’s immutable built-in objects are hashable, while no mutable containers (such as lists or dictionaries) are. Objects which are instances of user-defined classes are hashable by default; they all compare unequal (except with themselves), and their hash value is derived from their id().
EDIT, based on the discussion below, to avoid confusion:
* hashable in the sense that when you pass object to hash() function it will not raise error, not that it is instance of collections.abc.Hashable and provide __hash__() method
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs