Exact error codes for mypy errors
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with mypy's existing --show-error-code behavior and the sample.py and mytest.py examples in the issue. Define a stable numeric code for each distinct error and ensure every reported error displays it before the message, with coverage for the existing error cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100