Support conditionally importing from typing_extensions
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- Ø Merge
- 1 T. 18 Std.
- Gemergte PRs (30 T.)
- 54
Beschreibung
This code tries to import TypeAlias from typing if possible and falls back to typing_extensions if it isn't available (e.g. on Python 3.8):
try:
from typing import TypeAlias # type: ignore
except ImportError:
from typing_extensions import TypeAlias
Mypy doesn't actually support this as expected in older Python versions that are missing the definition in typing. They will just get an Any value, and the except block has no significance.
Perhaps the import from typing_extensions should take precedence? Or can we at least generate a more specific error about this?
A possible workaround is to flip the order of the imports.
This probably affects any feature that requires an import of a backported definition from typing_extensions.
Related issue: #14219
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
Es wird keine Datei, kein Test und kein Einstiegspunkt genannt. Beginne mit der Überprüfung des hier beschriebenen bedingten TypeAlias-Importverhaltens und des zugehörigen Issues #14219; bestimme, ob ein Importvorrang oder eine Diagnose vorgesehen ist, und überprüfe anschließend das gewählte Verhalten für ältere Python-Versionen.
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
- Muss geklärt werden
- Anfängerfreundlichkeit
- 35/100