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

Pylance is linting standard library and venv site-packages #1514

Closed
Spitfire1900 opened this issue Jul 1, 2021 · 17 comments
Closed

Pylance is linting standard library and venv site-packages #1514

Spitfire1900 opened this issue Jul 1, 2021 · 17 comments
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@Spitfire1900
Copy link

Spitfire1900 commented Jul 1, 2021

Environment data

  • Language Server version: v2021.6.3
  • OS and version: Windows 10 x64 1910
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.4

Expected behaviour

Only the current workspace, excluding site-packages should be linted for issues.

Actual behaviour

Pylance is linting the standard library and venv site-packages

Logs

pylance log.txt

image
image

@github-actions github-actions bot added the triage label Jul 1, 2021
@bschnurr
Copy link
Member

bschnurr commented Jul 5, 2021

by default pylance should only be returning diagnostics for "opened" files.

can you confirm you haven't set this setting to something besides openFilesOnly?

settings.json

"python.analysis.diagnosticMode": "openFilesOnly",

@bschnurr bschnurr added the waiting for user response Requires more information from user label Jul 5, 2021
@github-actions github-actions bot removed the triage label Jul 5, 2021
@jakebailey
Copy link
Member

It also shouldn't show those files even in workspace diagnostics mode, so long as that interpreter is selected.

@Spitfire1900
Copy link
Author

This has been reproduced with both diagnostic modes.

@erictraut
Copy link
Contributor

The log shows that c:\Users\ACCOUNT\Repos\WORKSPACE\.venv is being auto-excluded (presumably because it's the selected Python environment).

I'm unable to reconcile the screen shot above with the provided logs. In particular, the files displayed in the "Problems" section in the screen shot are not mentioned in the log, which means that pylance has not opened or analyzed those files. For example, os.py does not appear anywhere in the log.

@Spitfire1900
Copy link
Author

I noticed, but some are, such as json\decoder.py

@Spitfire1900
Copy link
Author

What's also been observed is that this doesn't happen immediately, or always happens even. When it does happen it's frequently 10-15min after the project had been opened.

@erictraut
Copy link
Contributor

Do you remember ever opening these files in the editor?

Also, could you please answer the question asked by @bschnurr above? Is "python.analysis.diagnosticMode" set to the default value of "openFilesOnly", or have you changed it to "workspace"?

@Spitfire1900
Copy link
Author

  1. Do you remember ever opening these files in the editor?
    A. When opening a stdlib file this does reproduce, for example doing a "Go to definition" on logging.getLogger() will trigger C:\Program Files\Python39\Lib\logging\__init__.py to be linted, the errors are retained in the Problems pane after closing logging\__init__.py
  2. Also, could you please answer the question asked by @bschnurr above? Is "python.analysis.diagnosticMode" set to the default value of "openFilesOnly", or have you changed it to "workspace"?
    A. This is with "python.analysis.diagnosticMode": "workspace" set in the workspace's settings.json. However this reproduces with 'openFilesOnly' (but only for the file that was opened, references are not followed).

Doing a "Go to definition" on a method reference when "python.analysis.diagnosticMode": "workspace" is set is what triggers this issue.

The easiest way to reproduce this is to "Go to Definition" on jinja2.filters while "python.analysis.diagnosticMode": "workspace" is set.

@jakebailey
Copy link
Member

Thanks for the info. The errors being retained on file close is the bug, but I can't seem to reproduce it on my machine using any of my available interpreters. Closing the open file always hides the diagnostics, so I don't know what's going on there.

(Sounds similar in behavior to #1404, but that's triggered by some yet-to-be-known behavior.)

@Spitfire1900
Copy link
Author

On systems with slower harddrives or especially aggressive AV on-demand scanners this behavior also will trigger heavy bottlenecking of harddisk or CPU respectively.

@jakebailey
Copy link
Member

I don't see how any of this has anything to do with performance. We will only analyze the files when they are opened or changed; the stdlib is stubbed, so we don't analyze the files that are in your screenshots unless they are explicitly opened, and the stdlib doesn't change, so we won't do any more work than we are required to do.

@jakebailey
Copy link
Member

I think @erictraut figured this out and fixed it in microsoft/pyright@d01295d, but we can see in today's release.

@jakebailey jakebailey added fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed waiting for user response Requires more information from user labels Jul 14, 2021
@bschnurr
Copy link
Member

This issue has been fixed in version 2021.7.3, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202173-14-july-2021

@Spitfire1900
Copy link
Author

Spitfire1900 commented Aug 25, 2021

I am working on identifying the reproduction workflow but it looks like this issue or a variant of it has regressed on my instance.

image

@Spitfire1900
Copy link
Author

I am working on identifying the reproduction workflow but it looks like this issue or a variant of it has regressed on my instance.

@IrfanAkram5
Copy link

I was going to comment that I too have been having this issue( running VS code with a miniconda venv on WSL2 ) for a couple of months. See example picture: My workaround had been to switch to the Jedi language server.

Pylance - Screenshot 2021-08-31 171340

On further trying today, it was the "python.analysis.diagnosticMode": "openFilesOnly" after all! On my User tab setting, it was set to workspace, whilst in Remote and Workspace tab settings, it was "openFilesOnly". Once it was synced across the board to "openFilesOnly", it stopped analyzing everything. Hopefully it helps anyone facing same issue.

@Spitfire1900
Copy link
Author

Unfortunately "python.analysis.diagnosticMode": "openFilesOnly" isn't a valid workaround. If you're entire project is error free setting it to workspace detects api breakages across modules to the file you're editing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

5 participants