attr.asdict -> attrs.asdict regression for sets of instances
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- python
- Domain
- developer-experience
Research direction
Run the supplied Python reproducer first to confirm the TypeError. Then read attr/_next_gen.py and attr/_funcs.py, which appear in the traceback, and trace how attrs.asdict handles the set of Foo instances. Done means attrs.asdict(Bar({Foo(3)})) converts successfully without the unhashable-dict failure.
Written by the indexing model from the issue text.
Description
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)})))
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-attrs/attrs
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-attrs/attrs#1620 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
python-attrs/attrs#1596 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1549 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
python-attrs/attrs#1543 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1532 ·
All issues in python-attrs/attrs
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100