attrs plugin does not implement the new attributes collection algorithm
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit mypy's attrs plugin und reproduziere das gemeldete Beispiel für Mehrfachvererbung mit attrs.define, field und collect_by_mro=True. Vergleiche die inferierte Konstruktorsignatur mit dem erwarteten Verhalten D(f: int), und füge Tests hinzu oder aktualisiere die Testabdeckung so, dass der positionale Aufruf die Typprüfung besteht, während das bestehende non-collect_by_mro-Verhalten korrekt bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100