python / python/mypy

Deprecate type comment support?

Offen
#12,947 6 Kommentare 5 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

needs discussion topic-parser
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

I've kicked off a discussion on typing-sig, as some of you have already seen, to talk about deprecating and eventually removing type comments.

Currently, the ast module takes type_comments=True to enable parsing any type comment.

I am proposing that this argument emit deprecation warnings with Python 3.12 and 3.13. With Python 3.14 type_comments=True will be removed, and all type comments except for # type: ignore will be treated as normal comments. (# type: ignore will always parse as its own node in the parser).

There is a complication: ast.parse also accepts feature_version. 3.11 is not EOL until 2027, so if someone wanted to parse code written targeting 3.11 with a mypy running on, say 3.14, that would not work under my proposal. I believe that this is acceptable, because the user would have 2 reasonable alternatives: 1) type check their code targeting 3.11 with mypy running on 3.11 2) update to type annotations, which they will need to do eventually anyway, and would have 3 years to do so already.

I think the existing tooling such as libcst, pyupgrade, com2ann, etc make the upgrade relatively straight forward.

I'd be interested to hear what others think mypy should do in regards to removing support for type comments (or if we should at all!)

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

Beginne mit der verlinkten typing-sig-Diskussion und dem Vorschlag des Issues für ast.parse(type_comments=True) sowie das Verhalten von feature_version. Ermittle, ob mypy die Unterstützung für Typkommentare entfernen sollte und welche Kompatibilitätsrichtlinie erwartet wird; abgeschlossen ist die Aufgabe, wenn eine einvernehmliche Entscheidung und der entsprechende Implementierungsumfang feststehen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

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