Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make column/line numbers more precise for common errors #7053

Closed
JukkaL opened this issue Jun 24, 2019 · 3 comments
Closed

Make column/line numbers more precise for common errors #7053

JukkaL opened this issue Jun 24, 2019 · 3 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 24, 2019

In some cases mypy error messages don't point to the expected location, especially when using --show-column-numbers. Example:

def f(x: int) -> None: pass

# Mypy message points to 'f' at the beginning of the line
f(
    'foo')     
  # ^ I'd expect the error point to 'foo' here

This is a significant usability issue when running mypy from an editor, especially if error locations are highlighted in the code. Having the correct line number would help usability in general, however.

It would be good to go through selected common error messages, such as invalid argument, undefined name, missing attribute, and incompatible assignment, and make sure that the line/column numbers point to the correct part of the expression/statement.

Note that this may break existing # type: ignore comments. I don't think that there's a way around this, other than perhaps providing a tool that can automatically move # type: ignore comments to the new locations.

This is basically a subset of existing issues #4276 and #4829. The original issues are too wide-ranging to be actionable in the short term, but fixing a few common messages would solve perhaps 80% of the problem without much effort.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jun 28, 2019

Some of this has been implemented in #7078 and #7081. I'm also working on another PR, but it turned out to be a bit harder than expected.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Sep 27, 2019

#7569 and #7470 improved error locations for return statement and incompatible arguments.

JukkaL added a commit that referenced this issue Oct 7, 2019
Most notably, report more precise error locations for incompatible
return value types and incompatible default argument values.

Also add some tests.

Work towards #7053.
@JukkaL
Copy link
Collaborator Author

JukkaL commented Jan 29, 2020

This seems good enough now. We can create additional issues about specific contexts where line/column numbers are still imprecise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant