-
Notifications
You must be signed in to change notification settings - Fork 35
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
Some caching occurs when using pylint in a server like mode. #129
Comments
@ChienTeLee This extension shows whatever we get from |
I tried to create a reproducer for #132, but found that the extensions creates a different result compared to a manual invocation. I think it might be related to the bug reported here, but I'm not sure. For: ❯ cat test.py
def func(param: int) -> int:
return param
❯ cat test2.py
import test
test.func(1)
Note that I removed Edit: I also tried with ❯ cat test2.py | /Users/daniel/.pyenv/versions/3.10.0/envs/pylint-3.10.0/bin/python -m pylint --reports=n --output-format=json --from-stdin /Users/daniel/DocumentenLaptop/Programming/Github/pylint/test2.py
[] So same difference.. |
@DanielNoord Can you dump what You should be able to find the |
❯ cat test2.py | /Users/daniel/.pyenv/versions/3.10.0/envs/pylint-3.10.0/bin/python -m pylint --reports=n --output-format=json --from-stdin /Users/daniel/DocumentenLaptop/Programming/Github/pylint/test2.py
['/Users/daniel/DocumentenLaptop/Programming/Github/pylint',
'/Users/daniel/.pyenv/versions/3.10.0/lib/python310.zip',
'/Users/daniel/.pyenv/versions/3.10.0/lib/python3.10',
'/Users/daniel/.pyenv/versions/3.10.0/lib/python3.10/lib-dynload',
'/Users/daniel/.pyenv/versions/3.10.0/envs/pylint-3.10.0/lib/python3.10/site-packages',
'/Users/daniel/DocumentenLaptop/Programming/Github/pylint',
'/Users/daniel/DocumentenLaptop/Programming/Github/astroid']
[] Just before we actually start checking the file. diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py
index e2bbf061e..092bdd6f9 100644
--- a/pylint/lint/pylinter.py
+++ b/pylint/lint/pylinter.py
@@ -715,6 +715,9 @@ class PyLinter(
:param FileItem file: data about the file
:raises AstroidError: for any failures stemming from astroid
"""
+ import sys
+
+ print(sys.path)
self.set_current_module(file.name, file.filepath)
# get the module representation
ast_node = get_ast(file.filepath, file.name) |
/Users/daniel/.vscode/extensions/ms-python.pylint-2022.3.11671003/bundled/linter
/Users/daniel/.pyenv/versions/3.10.0/lib/python310.zip
/Users/daniel/.pyenv/versions/3.10.0/lib/python3.10
/Users/daniel/.pyenv/versions/3.10.0/lib/python3.10/lib-dynload
/Users/daniel/.pyenv/versions/3.10.0/envs/pylint-3.10.0/lib/python3.10/site-packages
/Users/daniel/DocumentenLaptop/Programming/Github/pylint
/Users/daniel/DocumentenLaptop/Programming/Github/astroid
/Users/daniel/.vscode/extensions/ms-python.pylint-2022.3.11671003/bundled/libs @karthiknadig How can I read anything printed to |
I noticed something strange as well. I'm using an editable instal However, whenever I make changes to those installs they don't get used by the extension. I need to restart the server for those changes to take effect. Furthermore, the ['/Users/daniel/DocumentenLaptop/Programming/Github/pylint',
'/Users/daniel/.pyenv/versions/3.10.0/lib/python3.10',
'/Users/daniel/.pyenv/versions/3.10.0/lib/python3.10/lib-dynload',
'/Users/daniel/.pyenv/versions/3.10.0/envs/pylint-3.10.0/lib/python3.10/site-packages',
/Users/daniel/DocumentenLaptop/Programming/Github/astroid',
'/Users/daniel/DocumentenLaptop/Programming/Github/pylint',
'/Users/daniel/.vscode/extensions/ms-python.pylint-2022.3.11671003/bundled/libs'] This could be because of the changes to |
@DanielNoord for diagnostic purposes, I dump everything that i get from vscode-pylint/bundled/linter/linter_server.py Line 258 in 9d05b8e
If you want verbose logging then add |
I believe this might be due to |
Yeah, some of the caching in |
@brettcannon Any suggestions here on how we can do reload safely? |
For completeness I captured the sys.path for the ways of running pylint that we were looking at: Running pylint as a module in terminal:
Using runpy.run_module
Via the extensionThe typescript part launches this
The only thing missing from the sys.path in the extension |
No, because runpy isn't directly designed for this scenario; it's meant to handle One potential way to solve this would be to call One, you have to do it for all relevant modules, not just Two, this will only work if the code imported the module and not objects off the module. For instance, if |
@jacobtylerwalls You have a better understanding of clearing caches within |
Should be as simple as calling This should be done after every pylint call. Can we try that here? If that doesn't work, then there's still a global state somewhere we don't know about (or we need to look into Brett's tip about importing off the module and verify it's not that). This is all assuming a single-process scenario. There are many known issues with parallel mode in @DanielNoord we could look into some usability improvements, either always clearing the cache at the end of a run, and/or providing a kwarg argument to opt in to retaining the cache. WDYT? |
@jacobtylerwalls Seems like an option |
Yep, that should be doable. We can probably handle it somewhere in vscode-pylint/bundled/linter/utils.py Lines 112 to 134 in 9d05b8e
We are running single-threaded, so that's not a concern here (perk of Pylint being run in a language server and those out-of-process to VS Code itself). |
Is this still being investigated? I have the same issue when doing refactoring in a project. Every time I change the name of a class, function or method that is imported elsewhere, I need to reload pylint to clear the error that is sure to show up after I save the changes, which triggers linting of the open files. |
@DanielNoord did any flag ever end up in Pylint? Or should we just hack up a forced reload of the appropriate modules? |
I put pylint-dev/pylint#7802 up just now as a proof of concept. |
Does anybody from the team want to try out the new flag? We could put it an a patch release and get it out relatively easily, but since your the main target for this flag we'd like to get confirmation that we did indeed fix the issue. If not, we could try and find something else! |
We might not have time to get to this until January, but we will definitely give it a try when we can! No need to do a point release just for us. |
Thanks for getting back! I'll guess we'll just merge then and release at some point before January. We think this fits the use case, but don't hesitate to tell us if we missed anything! |
@DanielNoord Which version of pylint has the flag? |
2.16, which hasn't been released yet. See pylint-dev/pylint#7802 |
We're planning on releasing 2.16.0 soonish ™️ |
Hi, I just installed this extension and work on python 3.8.11. When I use relative import to import a file which have the same name with another file in other folder, pylint cannot import correctly and showing false positives. This happens globally, and I think it is the same issue with this one: pylint-dev/pylint#5645.
The text was updated successfully, but these errors were encountered: