Regression with `UnionType` as arg from 1.18.2 to 1.19.0
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
Regression with UnionType from 1.18.2 to 1.19.0, get an error when a union is directly used as an argument typed as UnionType, but not when stored in a variable.
To Reproduce
Playground gist: https://gist.github.com/mypy-play/cd116c86100702e51bc18fe78f0de638
Im below example, foo(example) is fine but foo(int | str) raises an error
from types import UnionType
def foo(t: UnionType) -> None:
pass
example = int | str
foo(example)
foo(int | str)
Expected Behavior
No errors
Actual Behavior
example.py:11: error: Argument 1 to "foo" has incompatible type "UnionType | type[int]"; expected "UnionType" [arg-type]
Your Environment
- Mypy version used: 1.19.0
- Mypy command-line flags: n/a
- Mypy configuration options from
mypy.ini(and other config files):
[mypy]
plugins = pydantic.mypy
ignore_missing_imports = True
disallow_untyped_calls = True
disallow_untyped_defs = True
disallow_incomplete_defs = True
check_untyped_defs = True
warn_unused_ignores = True
warn_no_return = True
warn_return_any = True
warn_redundant_casts = True
strict_equality = True
- Python version used: 3.13.2
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 der minimalen Reproduktion im Issue oder in dessen verlinktem Playground-Gist und vergleiche ihr Verhalten unter mypy 1.18.2 und 1.19.0. Verfolge, wie ein direktes int | str-Argument im Vergleich zur Variable example inferiert wird, und füge einen Regressionstest hinzu, der beide Aufrufe abdeckt; fertig ist es, wenn mypy für die Reproduktion keine Fehler meldet.
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
- 38/100