python / python/mypy

Exact error codes for mypy errors

Aperta
#10,843 10 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature needs discussion
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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 001 though 080 for 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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il comportamento esistente di mypy per --show-error-code e con gli esempi sample.py e mytest.py nell'issue. Definisci un codice numerico stabile per ogni errore distinto e assicurati che ogni errore segnalato lo visualizzi prima del messaggio, con una copertura per i casi di errore esistenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.