Feature request: option that prohibits any use of type:ignore, and other type-checking-suppression mechanisms
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Feature
PEP 484 lists several ways to ignore type checking https://peps.python.org/pep-0484/#compatibility-with-other-uses-of-function-annotations:
# type: ignorecomment- a
@no_type_checkdecorator on a class or function - a custom class or function decorator marked with
@no_type_check_decorator
I would like an option that disallows all of these methods, eg --disallow-type-ignores
Pitch
My basic idea here is that I want to actually enforce typing and have it completely statically verified, when possible. If that isn't happening, I'd like to know! And possibly refactor my code to remove the ignores. — I would like mypy to be able to tell me whether or not my types are completely automatically enforced, without any ignores, if I use the right flag. This seems like an ergonomic way to enable that. (There are probably other ways to cheat the python type checker that could also be ruled out, with other flags.)
While useful, these type-checker-ignore features get around static type safety without ensuring dynamic type correctness, which is not ideal. Sometimes you have to use them—you know how it is—but it's not ideal. That means, in my opinion, it would be great to have a option for disallowing their use, to ensure mandatory type-safety in codebases where these workarounds are not in fact needed.
I don't think it would make sense to turn this option on by default, nor in strict mode. The ecosystem of typing just isn't thorough and unimpingable enough, in my experience. It could maybe make sense to go in some hypothetical ultrastrict mode, but I don't think most strict mode users would benefit from this option being turned on.
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
Überprüfe die im Issue aufgeführten PEP-484-Unterdrückungsmechanismen und verfolge, wo mypy Befehlszeilenoptionen und die Unterdrückung der Typprüfung behandelt. Definiere den Geltungsbereich und das Verhalten der Option für type: ignore, @no_type_check und @no_type_check_decorator und füge Testabdeckung hinzu, die zeigt, dass jeder Mechanismus abgelehnt wird, wenn die Option aktiviert ist.
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