You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
print, others flagged as "Undefined variable" (requests being handled before initialization is complete?) #1697
OS and version: Microsoft Windows [Version 10.0.18362.418]
Python version (& distribution if applicable, e.g. Anaconda): Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32
Expected behaviour
print should NOT be flagged as "Undefined variable"
I am having a similar issue with inbuilt functions and types such as ValueError and float. I tried changing the settings as described above to Trace and this made the Undefined Variable error go away.
Changing the logging setting wouldn't have any effect. If you reloaded the editor when you changed the setting, the reload is what would have likely fixed it.
To be clear, after disabling caching, did you restart the language server? I don't know if we currently handle the case of going from caching to no caching within the same run (the other way would work, though be less efficient).
Essentially this appears to be happening to anything that's declared in the global scope; things like print, str, and len, aren't "keywords" per se, but actual variables that exist in the scope and can be reassigned like any other variable, so we declare them in every module before analyzing. That's what appears to either not happen, or get lost along the way.
Working on #1601 and #1414 may preclude this, since they affect the analysis order.
No improvement for me. Builtins are still undefined and analyzing in background gets stuck. It seems that this only happens in big projects. I have no problems in smaller (less number of files) project.
Another possible reason is that cached generated stub for builtins is empty or damaged. pyi. This is unrelated to caching None since that setting controls caching of analysis rather than stubs generated from the compiled modules. Chris Kuenneth (@kuelumbus) - try deleting everything in /home/chris/.cache/Microsoft/Python Language Server.
However, I still see
Analysis of builtins (Builtins) on depth 0 completed in 365.12 ms.
No change. I removed the cache and restarted Code. Right after the restart, the builtins were correctly flagged showing their correct doc strings. A cup of coffee later, the builtins are again flagged as undefined variable.
Somehow your workspace is a symlink to somewhere completely different outside of the workspace? What kind of setup do you have in your pythonpath? This seems very unusual.
Try setting "python.analysis.watchSearchPaths": false to disable file watching.
There are no symlinks in the workspace but /home/chris/data is a link to /data/chris. The workspace is accessible by /home/chris/data/ml/Net and /data/chris/ml/Net. Could this be the issue?
as the symptom is that builtins are wrongly flagged as not defined, i don't see why this issue is being closed. the problem is still there, isn't it? That the underlying reason maybe (i don't know i'm not the developer) has nothing to do with built-ins isn't really the user's problem.
The builtins were being flagged as undefined as they hadn't been properly created, meaning users of the builtin wouldn't see that they exist and then show messages.
Indefinite reloads may or may not cause that issue (usually not, just infinite analysis), and IMO are not necessarily related. The infinite reload observed above was described as "the docstrings don't show up", not "things are shown as undefined"; if the analysis never completes it won't show linting messages. If it completes with bad state, then you'll get wrong messages, which is what the original issue described and should be fixed with the merged PR.
I can see that you mentioned self being marked as undefined; That sounds like another issue we would want a reproducer for. self is not a part of the builtins code (which is what is fixed), but something different.
If your issue persists, then we'd appreciate a new issue to take a look. (We prefer new issues that we can triage and merge, rather than lumping similar symptoms together in a single never-closed issue.)
Activity
jakebailey commentedon Oct 16, 2019
Could you please provide the logs asked for in the template? I'd like to see the caching level you are using.
JoeCodeswell commentedon Oct 16, 2019
Hi Jake. Thanks for the response. I think you want me to follow:
So I did Python › Analysis: Log Level
Defines type of log messages language server writes into the output window.
Trace
And Here's Output.Python:
I hope this is what you wanted.
Thanks again, Jake.
Love and peace,
Joe
JoeCodeswell commentedon Oct 16, 2019
I just did a second run of my program just to be sure. Here's Output.python again.
jakebailey commentedon Oct 16, 2019
I see, you don't have trace logging enabled and I think you're in the wrong output tab. Add
"python.analysis.logLevel": "Trace"to your settings and reload, and your logs should be more verbose. You can find them in the "Python Language Server" part of the output panel (in the dropdown). See: https://github.com/microsoft/python-language-server/blob/master/TROUBLESHOOTING.md#filing-an-issueJoeCodeswell commentedon Oct 16, 2019
Hi Jake. Thanks for your patience. I just
I reopened the "offending" program == test_jsonschema.py & NOW print IS NOT FLAGGED as Undefined variable!
How time flies when you're having fun!
I just ran test_jsonschema.py
Now i open OUTPUT & select THE SECOND Python Language Server entry in the dropdown. N.B. the first had no output in the window.
Here is what the OUTPUT window says:
I am attaching the output as vscodePyLangServerLog.txt
vscodePyLangServerLog.txt
jakebailey commentedon Oct 17, 2019
Caching is disabled in those logs, so that's interesting.
Reloading fixing it doesn't surprise me, as the analysis will have been rerun.
sdpenguin commentedon Oct 21, 2019
I am having a similar issue with inbuilt functions and types such as
ValueErrorandfloat. I tried changing the settings as described above to Trace and this made theUndefined Variableerror go away.jakebailey commentedon Oct 21, 2019
Changing the logging setting wouldn't have any effect. If you reloaded the editor when you changed the setting, the reload is what would have likely fixed it.
pcolmer commentedon Oct 22, 2019
I'm having the same problem of "print" being marked as an undefined variable.
Trace output attached.
trace-logs.txt
kuelumbus commentedon Oct 22, 2019
I can confirm this problem. I am having it for all built-ins (dict, len, print, list, ...) ?
python.analysis.cachingLevelis set toNoneto fix #1601 .jakebailey commentedon Oct 22, 2019
To be clear, after disabling caching, did you restart the language server? I don't know if we currently handle the case of going from caching to no caching within the same run (the other way would work, though be less efficient).
kuelumbus commentedon Oct 23, 2019
Thanks. I did restart. Also, I find
[Info - 9:35:07 AM] Analysis caching mode: None.in the log file.BTW, analyzing in background is now very slow. It takes hours to finish and afterward, I am having the
Undefined variable ...problem.eerovil commentedon Oct 24, 2019
I'm having the same problem, but reloading resolves it. For now I have to reload every hour or so.
markedwards commentedon Oct 25, 2019
This issue appears to affect many basic Python objects, like

str. Attaching screenshot.jakebailey commentedon Oct 25, 2019
Essentially this appears to be happening to anything that's declared in the global scope; things like
print,str, andlen, aren't "keywords" per se, but actual variables that exist in the scope and can be reassigned like any other variable, so we declare them in every module before analyzing. That's what appears to either not happen, or get lost along the way.Working on #1601 and #1414 may preclude this, since they affect the analysis order.
31 remaining items
kuelumbus commentedon Nov 14, 2019
No improvement for me. Builtins are still undefined and analyzing in background gets stuck. It seems that this only happens in big projects. I have no problems in smaller (less number of files) project.
Trace log
MikhailArkhipov commentedon Nov 14, 2019
Another possible reason is that cached generated stub for
builtinsis empty or damaged.pyi. This is unrelated to cachingNonesince that setting controls caching of analysis rather than stubs generated from the compiled modules. Chris Kuenneth (@kuelumbus) - try deleting everything in/home/chris/.cache/Microsoft/Python Language Server.However, I still see
way at the end. This is the root, IMO.
kuelumbus commentedon Nov 14, 2019
No change. I removed the cache and restarted Code. Right after the restart, the builtins were correctly flagged showing their correct doc strings. A cup of coffee later, the builtins are again flagged as undefined variable.
MikhailArkhipov commentedon Nov 16, 2019
Could you try daily channel with 0.4.121? https://github.com/microsoft/python-language-server/wiki/Versioning-and-download-channels
kuelumbus commentedon Nov 16, 2019
Version 0.4.121 fixed it for me. However, I almost never see the doc string because it's constantly analyzing.
log.log
jakebailey commentedon Nov 17, 2019
Now it's stuck in a reload loop. Note:
Somehow your workspace is a symlink to somewhere completely different outside of the workspace? What kind of setup do you have in your pythonpath? This seems very unusual.
Try setting
"python.analysis.watchSearchPaths": falseto disable file watching.kuelumbus commentedon Nov 17, 2019
There are no symlinks in the workspace but
/home/chris/datais a link to/data/chris. The workspace is accessible by/home/chris/data/ml/Netand/data/chris/ml/Net. Could this be the issue?kuelumbus commentedon Nov 17, 2019
resolved it. But also changing the workspace root to the direct path.
Thanks for your help.
MikhailArkhipov commentedon Nov 17, 2019
OK, since reload is a different issue, I am going to close this one which is about builtins. Feel free to open new issue on reloads.
#1798
michaelaye commentedon Nov 17, 2019
as the symptom is that builtins are wrongly flagged as not defined, i don't see why this issue is being closed. the problem is still there, isn't it? That the underlying reason maybe (i don't know i'm not the developer) has nothing to do with built-ins isn't really the user's problem.
jakebailey commentedon Nov 17, 2019
The builtins were being flagged as undefined as they hadn't been properly created, meaning users of the builtin wouldn't see that they exist and then show messages.
Indefinite reloads may or may not cause that issue (usually not, just infinite analysis), and IMO are not necessarily related. The infinite reload observed above was described as "the docstrings don't show up", not "things are shown as undefined"; if the analysis never completes it won't show linting messages. If it completes with bad state, then you'll get wrong messages, which is what the original issue described and should be fixed with the merged PR.
jakebailey commentedon Nov 17, 2019
I can see that you mentioned
selfbeing marked as undefined; That sounds like another issue we would want a reproducer for.selfis not a part of the builtins code (which is what is fixed), but something different.If your issue persists, then we'd appreciate a new issue to take a look. (We prefer new issues that we can triage and merge, rather than lumping similar symptoms together in a single never-closed issue.)
MikhailArkhipov commentedon Nov 18, 2019
selfissue is probably #1573juniorsaldanha commentedon Oct 23, 2020
I fixed this problem enabling "Python: Enable Linting" in vscode (Linux).
HOW TO:
Open "Command Palette" and search for "Python: Enable Linting" and turn on this feature.
Worked for me .
Instagram Twitter