Exact error codes for mypy errors
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Feature
Pylint / Flake8 style, unique error codes to be shown with every error that mypy raises.
Pitch
Mypy currently has ~40 general error names, that are shown next to the error if you pass the --show-error-code flag to mypy. For eg:
$ cat sample.py
def foo(a: str) -> str:
return '(' + a.split() + ')'
$ mypy sample.py --show-error-codes
sample.py:2: error: Unsupported operand types for + ("str" and "List[str]") [operator]
Found 1 error in 1 file (checked 1 source file)
But in total there's at least 80 probably around 400 unique error messages, each for a different kind of error.
The idea
- Create a proper list of numeric error codes, say
001though080for eg., identifying each error uniquely. - Have the error code shown directly before the error message in mypy output, just like
pylint,flake8, and others.
$ cat mytest.py
def a():
print(foo)
$ pylint mytest.py
************* Module mytest
mytest.py:1:0: C0114: Missing module docstring (missing-module-docstring)
mytest.py:1:0: C0103: Function name "a" doesn't conform to snake_case naming style (invalid-name)
mytest.py:2:10: E0602: Undefined variable 'foo' (undefined-variable)
[...]
$ flake8 mytest.py
mytest.py:1:1: D100 Missing docstring in public module
mytest.py:1:1: D103 Missing docstring in public function
mytest.py:2:11: F821 undefined name 'foo'
I've run the idea past @ethanhs and I'm told that this would be a great-to-have in mypy. I'm willing to contribute this, once I've run it past the mypy team 😄
cc @srijan-deepsource
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 mit dem bestehenden Verhalten von mypy bei --show-error-code und den Beispielen sample.py und mytest.py im Issue. Definiere für jeden einzelnen Fehler einen stabilen numerischen Code und stelle sicher, dass jeder gemeldete Fehler diesen vor der Meldung anzeigt, mit Abdeckung für die bestehenden Fehlerfälle.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100