attrs plugin does not implement the new attributes collection algorithm
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
The attrs plugin does not implement the new attributes collection algorithm that is enabled with @attr.s(collect_by_mro=True) in the old API and is the only option in the new API.
To Reproduce
(mypy-play.net does not have stubs for attrs)
from attrs import define, field
@define
class A:
f: int = field(kw_only=True)
@define
class B(A):
pass
@define
class C(A):
f: int = field()
@define
class D(B, C):
pass
# D(f: int) for attrs.define, but D(*, f: int) for attr.s
d = D(123)
print(d.f)
Expected Behavior
The signature for D should be D(f: int), so this should type check. It works fine at run time.
Actual Behavior
attrs_mro.py:20: error: Too many positional arguments for "D" [misc]
I get the same error if I replace @define and field with @attrs(collect_by_mro=True) and attrib from the old namespace respectively. Note that this behavior is correct when @attrs is used without collect_by_mro=True.
Your Environment
- Mypy version used: 1.5.1
- Python version used: 3.11
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.
Research direction
Start with mypy's attrs plugin and reproduce the reported multiple-inheritance example using attrs.define, field, and collect_by_mro=True. Compare the inferred constructor signature with the expected D(f: int) behavior, and add or update coverage so the positional call type-checks while the existing non-collect_by_mro behavior remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100