python / python/mypy

Since 1.6.0 TypeVar with bound types fails to match with Callable of the same bound types

Offen
#16,374 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Bug Report

Did not occur prior to 1.6.0.

https://github.com/python-cmd2/cmd2/actions/runs/6699406223/job/18203570049
Got the following error with mypy:

cmd2/cmd2.py: note: In member "_build_parser" of class "Cmd":
cmd2/cmd2.py:699:46: error: Argument 1 has incompatible type "CommandParent"; expected "Union[Type[Cmd], Type[CommandSet]]"  [arg-type]
Found 1 error in 1 file (checked 18 source files)

where CommandParent is a TypeVar declared as:

CommandParent = TypeVar('CommandParent', bound=Union['cmd2.Cmd', CommandSet])

To Reproduce

https://github.com/python-cmd2/cmd2/blob/8d88c357ca0764b114c68d8175d2cd33146b83d7/cmd2/cmd2.py#L694

Expected Behavior

Since CommandParent is bound to the expected type, this shouldn't be an error

Actual Behavior

I get the error above.

Your Environment

  • Mypy version used: 1.6.1
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.8, 3.9,3.10,3.11

Beitragsleitfaden

Beitragsleitfaden öffnen

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

Reproduziere den Fehler aus cmd2/cmd2.py um Zeile 694 mit mypy 1.6.1 und den gemeldeten Python-Versionen. Vergleiche die TypeVar-Bindung mit der Verarbeitung von Callable-Argumenten und überprüfe anschließend, dass die gemeldeten kompatiblen Typen nicht mehr den arg-type-Fehler erzeugen.

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
35/100

Neue Issues direkt in Ihr Postfach

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