When using`--disallow-any-expr`, silence complaints about Any where object would work
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Problem
Using Any is not type safe, therefore Mypy provides options to disallow Any. However, there are many uses of Any from third-party and stdlib, so these options tend to result in a lot of errors even when they are not relevant.
I'm finding many situations where I get an error about Any, but the code would be deemed safe if it was object.
Examples
This produces errors about Any on both lines even though the value is not used:
type_hints = typing.get_type_hints(...) # Dict[str, Any]
if k in type_hints:
...
This produces errors as well, but object would not produce errors, as Mypy can infer everything necessary here to be type safe.
origin = typing.get_origin(...) # Any
if origin is Literal:
...
elif origin is list:
...
Solution
Add an option, or change the behaviour of the current disallow Any options, such that Any is treated like object. Then, rather than producing errors when Any is present, just show normal errors with Any (as if it was object) in them (e.g. 'Any has no attribute foo').
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, die beiden Beispiele mit --disallow-any-expr zu reproduzieren und ihre Diagnosen mit äquivalenten object-Annotationen zu vergleichen. Überprüfe die bestehende Behandlung der disallow-Any-Optionen und definiere dann Tests dafür, Any wie object zu behandeln, während gewöhnliche Fehler wie fehlende Attribute beibehalten werden.
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
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100