attrs plugin does not implement the new attributes collection algorithm

Offen
#16,014 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
devtools

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.

Beschreibung

bug topic-attrs

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
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
Ø Merge
1 T. 18 Std.
Gemergte PRs (30 T.)
54

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python/mypy

Alle Issues in python/mypy

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.