Skip to content

Exact error codes for mypy errors #10843

Open
@tushar-deepsource

Description

@tushar-deepsource

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions