Python Forum
Creating a set with dataclass and dict
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a set with dataclass and dict
#1
Hi everyone.
I am trying to play with the new @dataclass and TypedDict from 3.7 and 3.8
But after searching and reading lots of documentation I cannot find a proper answer on this. I think the answer is simple but it's not clear to me.
Here the snippet:
from dataclasses import dataclass


@dataclass(frozen=True, eq=True, repr=False)
class Building:
    name: str
    property: dict


foo = Building(name="Test", property={"key": 10})
var = {foo}
and the error:
  File "<string>", line 3, in __hash__
TypeError: unhashable type: 'dict'
Ok the message is clear, but I don't understand why all nested element of a set need to be hashable. I don't find anything that tell me: a set take only hashable element that have itself hashable element

Obviously if I replace the property with a hashable object it works.

Thank you for your help

Hobbit
Reply


Messages In This Thread
Creating a set with dataclass and dict - by hobbitdur - Jan-15-2020, 05:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  append str to list in dataclass flash77 6 570 Mar-14-2024, 06:26 PM
Last Post: flash77
  Sort a dict in dict cherry_cherry 4 79,458 Apr-08-2020, 12:25 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020