micseydel, thank you for your kind help.
But I am not sure I understood your answer.
You speak about using set in set or dict key. That's not what I meant.
My problem is the line 11 of my code. I have a dataclass that is Hashable (frozen and eq to True), but I cannot use it as an element of my set.
But I am not sure I understood your answer.
You speak about using set in set or dict key. That's not what I meant.
My problem is the line 11 of my code. I have a dataclass that is Hashable (frozen and eq to True), but I cannot use it as an element of my set.
import collections from dataclasses import dataclass @dataclass(frozen=True, eq=True, repr=False) class Building: name: str property: dict foo = Building(name="Test", property={"key": 10}) print(isinstance(foo, collections.Hashable)) var = {foo}
Output:F:/Perso/Python/board-game-solver/les-batisseurs/src/test.py:12: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
print(isinstance(foo, collections.Hashable))
Traceback (most recent call last):
File "F:/Perso/Python/board-game-solver/les-batisseurs/src/test.py", line 13, in <module>
var = {foo}
File "<string>", line 3, in __hash__
TypeError: unhashable type: 'dict'
True
Process finished with exit code 1
Thank you again !