(🎁) `isinstance`/`issubclass` only accept `typing.Union`s of `type`s, not other type forms
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Until type forms are properly supported by the type system, I wonder if this could be special cased?
from typing import Any
isinstance(1, str | Any) # no error, fails at runtime with TypeError: typing.Any cannot be used with issubclass()
FYI mypy is incorrectly inferring this as a types.UnionType but it is actually a typing.Union(#12369), I don't think you can have a UnionType with type forms in it.
PyCharm correctly warns here:

related: python/typeshed/issues/7505
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
Reproduziere das Beispiel isinstance(1, str | Any) und vergleiche mypys inferierten types.UnionType mit dem im Issue beschriebenen Laufzeitverhalten. Lies das zugehörige typeshed-Issue #7505 und verfolge den Typprüfpfad für isinstance und issubclass; fertig ist die Aufgabe, wenn die unterstützten Typformen konsistent behandelt werden, ohne den gemeldeten ungültigen Fall zuzulassen.
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