python / python/mypy

Feature request: option that completely disallows typing.cast

Offen
#17,077 11 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature topic-casts
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Feature

An option that disallows use of typing.cast, eg --disallow-casts

Pitch

cast() gets around static type safety without ensuring dynamic type correctness. Sometimes you have to use it—you know how it is—but it's not ideal. (For instance, mypy documentation seems to imply the main use of cast is when the typechecker or type annotations aren't quite good enough.) That means, in my opinion, cast is a great candidate to have a option disallowing its use, to ensure code quality in codebases where it is not needed.

I also think this option should be enabled in strict mode, but I suspect other people might disagree.

This proposal is distinct from the --warn-redundant-casts option that already exists, but is somewhat similar.

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 damit, zu überprüfen, wie die bestehende --warn-redundant-casts-Option implementiert ist, und lies die Diskussion darüber, ob dies in den strict mode gehört. Lege fest, wie typing.cast behandelt werden soll und wie sich die Konfiguration verhält, und überprüfe anschließend, dass die neue Option Casts ablehnt und dass das gewählte Verhalten im strict mode durch Tests abgedeckt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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