Conditionally excluding backward incompatible syntax based on python version
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Feature
There doesn't seem to be a way to progressively provide improvements in libraries that support older versions with syntactically backward incompatible code that is conditionally included at runtime.
For example in pythons < 3.12 it's not possible to exclude certain files containing PEP 695 type syntax even if the module is only imported with a sys.version_info >= (3,12) guard.
import sys
if sys.version_info >= (3, 12):
from _py312_types import A
else:
from _types import A
__all__ = ["A"]
# file: _py312_types.py
type A = list[int|A]
# file: _types.py
A = list[int|list["A"]]
Pitch
The only existing path that I could find was to allow python_version overrides on a per module basis (which is currently only acceptable as a global configuration) though that seems hacky and brittle.
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 damit, mypy's bestehende Konfiguration von python_version pro Modul nachzuverfolgen und zu untersuchen, wie es mit Imports umgeht, die durch sys.version_info geschützt sind. Im Issue werden keine Dateien oder Tests genannt; für die Erledigung wäre ein definierter und getesteter Ansatz erforderlich, um Module, die Syntax enthalten, die in älteren Python-Versionen nicht verfügbar ist, bedingt zu unterstützen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100