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

Support for output message ranges, instead of just the position #12288

Closed
DevilXD opened this issue Mar 4, 2022 · 4 comments
Closed

Support for output message ranges, instead of just the position #12288

DevilXD opened this issue Mar 4, 2022 · 4 comments
Labels

Comments

@DevilXD
Copy link

DevilXD commented Mar 4, 2022

Feature

Following the discussion in microsoft/vscode#142810, I propose MyPy to output a range over which a typing error occurs, instead of just the position of it. The current message with --show-column-numbers and --no-pretty looks like this:

test.py:4:5: error: Argument 1 to "foo" has incompatible type "str"; expected "int"

It'd be great if a range would be included for the column numbers, if possible:

test.py:4:5-15: error: Argument 1 to "foo" has incompatible type "str"; expected "int"

Output with --pretty could then use multiple ^ characters to visualize the range. Omitting --show-column-numbers wouldn't display column numbers at all, thus the output would remain unchanged.

Pitch

This change would allow the VSCode Python extension to output diagnostic objects with proper ranges, since the current implementation only underlines one character and makes it hard to work with, and other proposed solutions appear to be non-trivial at the very least.

@DevilXD DevilXD added the feature label Mar 4, 2022
@cdce8p
Copy link
Collaborator

cdce8p commented Mar 4, 2022

Some implementation considerations:

  • The end position should also contain a lineno in case the error stretches across multiple lines.
  • Only Python 3.8 added the end_lineno and end_col_offset attributes to AST nodes. It might not be practical to support it for 3.7

@JelleZijlstra
Copy link
Member

Agree that we should do this in Python versions where we have the right information in the AST.

@devmessias
Copy link
Contributor

I can address that.
About the use of multiple ^ in my project (pyastrx-alpha) I did something similar, take a look
image

The range of code shown is controlled by other parameters (context). For colors, I'm using rich, but I believe that is not a good idea to add a dependency in mypy.

@97littleleaf11
Copy link
Collaborator

Closed by #13148

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

No branches or pull requests

5 participants