Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attr.asdict -> attrs.asdict regression for sets of instances #1180

Open
jgarvin opened this issue Aug 25, 2023 · 2 comments
Open

attr.asdict -> attrs.asdict regression for sets of instances #1180

jgarvin opened this issue Aug 25, 2023 · 2 comments

Comments

@jgarvin
Copy link

jgarvin commented Aug 25, 2023

Hard coding retain_collection_types=True in attrs.asdict means that you can no longer convert objects that contain sets of other objects. Reproducer:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import attr
import attrs
from attrs import frozen

@frozen
class Foo:
    x: int

@frozen
class Bar:
    foos: set[Foo]

# works!
print(attr.asdict(Bar({Foo(3)})))

# fails with:
# Traceback (most recent call last):
#   File "/tmp/regression.py", line 16, in <module>
#     print(attrs.asdict(Bar({Foo(3)})))
#           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/home/x/.local/lib/python3.11/site-packages/attr/_next_gen.py", line 214, in asdict
#     return _asdict(
#            ^^^^^^^^
#   File "/home/x/.local/lib/python3.11/site-packages/attr/_funcs.py", line 75, in asdict
#     rv[a.name] = cf(
#                  ^^^
# TypeError: unhashable type: 'dict'
print(attrs.asdict(Bar({Foo(3)})))
@hynek
Copy link
Member

hynek commented Dec 29, 2023

To clarify: you're asking to get the knob back?

@jgarvin
Copy link
Author

jgarvin commented Dec 31, 2023

Really what I'm asking for is to be able to have an object that contains a set of other objects and still have asdict work, whether that's by putting the knob back or some other means. In a perfect world it would Just Work (TM) with no special options needed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants