Use of `AttrsInstance` protocol is incompatible with type checkers other than mypy
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 32/100
Research direction
Start by reproducing the type errors in fields and asdict with type checkers other than mypy, then read the AttrsInstance protocol and the attrs mypy plug-in behavior. Compare removing attrs_attrs from the protocol with injecting it through the plug-in; done means these core functions type-check by default outside mypy without breaking the attrs plug-in path.
Written by the indexing model from the issue text.
Description
The latest release introduced the AttrsInstance protocol with one attribute, __attrs_attrs__, which replaced Any in the signature of various core functions. The __attrs_attrs__ attribute is "injected" by the attrs mypy plug-in; other type checkers have no knowledge of this attribute and adding attributes to the type definition of a dataclass-like class is not supported by dataclass_transform. Therefore, functions such as fields and asdict generate type errors by default in all type checkers other than mypy. I am not familiar with mypy plug-ins but I assume one alternative would be to remove the attribute from the protocol definition and inject it dynamically from the plug-in, the way it's done for the attrs class. Longer term, an extension to dataclass_transform could be sought.
- 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
-
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
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100