Skip to content

Pylint not underlining full expressions in VS Code #3061

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

Closed
theodoretliu opened this issue Aug 13, 2019 · 4 comments
Closed

Pylint not underlining full expressions in VS Code #3061

theodoretliu opened this issue Aug 13, 2019 · 4 comments

Comments

@theodoretliu
Copy link

Steps to reproduce

  1. Create file with contents
from numpy import Array
1 + 2

in Visual Studio Code

  1. Enable pylint in settings.json by adding the following lines.
{
    ...
    "python.linting.enabled": true,
    "python.linting.pylintArgs": ["--enable=all"],
    ...
}
  1. See that pylint runs on the file created in step 1. Note the underlining.

Current behavior

Only the 1 in the "useless expression" is underlined. Only the from in the import statement is underlined.

Expected behavior

I would expect the entire "useless expression" - the 1 + 2 - to be underlined. I expect the entire import statement to be underlined.

I ran into this problem while developing a custom pylint extension. When I did self.add_message to a node of the AST, only the first token of that node ever got underlined, even if there were multiple tokens in that AST.

pylint --version output

pylint 2.3.1
astroid 2.2.5
Python 3.7.3 (default, Apr  9 2019, 18:48:27) 
[GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]
@PCManticore
Copy link
Contributor

Hi @theodoretliu This looks like an issue with VSCode rather than with pylint. FWIW, this is what I'm getting when running pylint over that code:

a.py:1:0: C0111: Missing module docstring (missing-docstring)
a.py:1:0: E0611: No name 'Array' in module 'numpy' (no-name-in-module)
a.py:2:0: W0104: Statement seems to have no effect (pointless-statement)
a.py:1:0: W0611: Unused Array imported from numpy (unused-import)

As you can see it correctly detects the cases you mentioned, but I'm afraid that VSCode itself might be doing something to hide certain errors from you.

@theodoretliu
Copy link
Author

So I agree that pylint is able to catch the errors. That wasn't the problem I was looking to report. I think the larger issue here is that pylint does not (and cannot) report the last line/character of the node that it marks. It only marks the starting line and character of the node that is problematic and sends that over to VS Code. Since VS Code only knows the starting location of the node, it does a "best effort" thing and only underlines the first token.

This seems to be a shortcoming of astroid and the Python ast module, where there is only col_offset but no corresponding from_col_offset and to_col_offset. Do you know if this is a possible feature to add?

@theodoretliu
Copy link
Author

It does seem like this broader issue of not having the ending col_offset and ending lineno is addressed by this PR on CPython itself. python/cpython#11605

It seems like Python 3.8 will have these notations in the AST, so until its official release and adoption, there's probably no easy fix to this problem.

@PCManticore
Copy link
Contributor

Thank you @theodoretliu for the explanation, that makes sense now. Indeed, most of the them we hit various shortcomings of ast and unfortunately there is no solution other than upgrading to the latest Python for getting those fixes.

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

No branches or pull requests

2 participants