This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author enaumov
Recipients enaumov
Date 2021-02-06.05:46:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1612590414.63.0.106701107905.issue43141@roundup.psfhosted.org>
In-reply-to
Content
A simple example is documented here: https://github.com/samuelcolvin/pydantic/issues/2233 but it doesn't look like it was actually filed as a bug against CPython... Copy paste of the minimal reproducing example:

from dataclasses import asdict, dataclass

@dataclass(eq=True, frozen=True)
class A:
  a: str

@dataclass(eq=True, frozen=True)
class B:
  b: dict[A, str]

asdict(B({A("x"):"y"}))


The offending code are these lines in dataclasses.py:

    elif isinstance(obj, dict):
        return type(obj)((_asdict_inner(k, dict_factory),
                          _asdict_inner(v, dict_factory))

The _asdict_inner(k, dict_factory) [correctly] turns dataclasses into dicts... which are not hashable. I assume there is a good reason the _asdict_inner function is called on the key, but its failure in this case looks like a (rather annoying!) error.
History
Date User Action Args
2021-02-06 05:46:54enaumovsetrecipients: + enaumov
2021-02-06 05:46:54enaumovsetmessageid: <1612590414.63.0.106701107905.issue43141@roundup.psfhosted.org>
2021-02-06 05:46:54enaumovlinkissue43141 messages
2021-02-06 05:46:54enaumovcreate