python / python/typing

Spec and conformance tests disagree on converting constructors into callable for classes with `__new__` and `__init__`

Offen
#2,158 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

topic: conformance tests topic: typing spec
Vorherrschende Sprache
Python
Sterne
1.8k
Forks
302
Ø Merge
23 Std.
Gemergte PRs (30 T.)
8

Beschreibung

For classes with both __new__ and __init__, when converting the constructor into a Callable, the spec says that

https://github.com/python/typing/blame/20096eeba502b1bf955fcf62b389adbaa63fc61b/docs/spec/constructors.rst#L457

    class B:
        """ __new__ and __init__ """
        def __new__(cls, *args, **kwargs) -> Self:
            ...

        def __init__(self, x: int) -> None:
            ...

    reveal_type(accepts_callable(B))  # ``def (*args, **kwargs) -> B | def (x: int) -> B``

The conformance test says that

https://github.com/python/typing/blob/20096eeba502b1bf955fcf62b389adbaa63fc61b/conformance/tests/constructors_callable.py#L54-L64

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Vergleiche das in docs/spec/constructors.rst rund um den verlinkten Abschnitt beschriebene Konstruktorverhalten mit dem Fall in conformance/tests/constructors_callable.py. Bestimme, welcher Callable-Typ für eine Klasse vorgesehen ist, die sowohl new als auch init definiert, gleiche anschließend Spezifikation und Konformitätstest aufeinander ab und führe die relevanten Konstruktor-Konformitätsprüfungen aus.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
documentation, testing-qa
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

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