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

Linting errors are not shown in VSCode, though simple errors do #2603

Closed
OfirD1 opened this issue Apr 19, 2022 · 3 comments
Closed

Linting errors are not shown in VSCode, though simple errors do #2603

OfirD1 opened this issue Apr 19, 2022 · 3 comments

Comments

@OfirD1
Copy link

OfirD1 commented Apr 19, 2022

Problem
Linting errors are not shown, while "simple" syntax errors are shown.

In the GIF below, you can see that the undefined variable message1 issues a warning, while the missing positional argument for hello doesn't issue the expected error - even after the file is saved, or after the undefined variable issue is fixed:

bug

What should I do to fix it?

Information

I'm on Windows 10, Python 3.8, VS Code 1.66.2.

To my understanding of this comment in microsoft/vscode-python's "Implement linting on change #408", I should see the aforementioned error, and moreover it should be displayed live, on text change (as opposed to on file save):

if you wish to use a language server that provides live linting, you can try our new and more performant language server called Pylance

Now, maybe something is wrong with my understanding or configuration, so here are some details (sorry if it's too verbose 😊):

1. Both the Python extension and the Pylance extension are installed

both are installed with their latest version:

image

2. Pylint is not installed

To my understanding, installing Pylint shouldn't be necessary. Nevertheless, I get the warning "Linter Pylint is not installed", as in this issue: #818 (which was closed because it was early days of Pylance):

image

I can ignore it, though.

3. Pylance is enabled

In my settings.json:

"python.languageServer": "Pylance"

4. Even if Pylint is installed, error is displayed thanks to Pylint, not to Pylance

I then tried to see what happens if I do install Pylint. This is what happens after installing it, and using the following in my settings.json:

"python.languageServer": "Pylance",
"python.linting.pylintArgs": [
      "--errors-only"
]

Note that Pylint is the one which issues the error (only on file save), and that the error disappears after the issue is fixed (again, only on file change):

image

Also, FWIW, I tried adding "python.linting.pylintEnabled": false:

"python.languageServer": "Pylance",
"python.linting.pylintEnabled": false,
"python.linting.pylintArgs": [
      "--errors-only"
]

But that just didn't have any effect, and what's displayed in the last GIF is what I still experienced (i.e. it seems like a Pylint issue, maybe somewhat related to the aforementiond #818, or to this Python extension issue).

@erictraut
Copy link
Contributor

Pylance isn't a "linter", at least not in the traditional sense of the word. Linting typically refers to checks for code style conventions, such as the conventions specified in PEP 8. Pylint is a good tool for linting.

Pylance does include a static type checker, which is designed to detect and report bugs in your code. By default, pylance shows only syntax errors and other errors that are guaranteed to cause undesired runtime exceptions (what you referred to as "simple errors").

You can also enable basic type checking diagnostics by setting "python.analysis.typeCheckingMode" to "basic". Once enabled, pylance will report basic type violations, such as passing the wrong number or wrong type of arguments to a function call. It sounds like you're looking for these checks. These are off by default in pylance because many users don't want the added noise of these errors.

We're looking at ways to make this setting more discoverable.

@judej judej closed this as completed Apr 19, 2022
@OfirD1
Copy link
Author

OfirD1 commented Apr 19, 2022

@erictraut I see, thank you!

Setting "python.analysis.typeCheckingMode": "basic" indeed works. Moreover, it works on text change (as opposed to Pylint, which only works on save).

However, VS Code still displays the "Linter Pylint is not installed" message, but I guess there's not much you can do with it on your side.

@erictraut
Copy link
Contributor

The "Pylint is not installed" message is because you have configured the Python extension to use Pylint. Look in your workspace or user settings for "python.linting.pylintEnabled": true, and change it to false. That should eliminate that message.

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

3 participants