Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
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

Description

Environment data

  • Language Server version: 0.4.71.0
  • 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"

Actual behaviour

print is flagged as "Undefined variable"

Logs

N/A

Code Snippet / Additional lnformation

vscodeUndefinedVar_print

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32

Activity

  1. jakebailey commented on Oct 16, 2019

    @jakebailey
    Member

    Could you please provide the logs asked for in the template? I'd like to see the caching level you are using.

  2. JoeCodeswell commented on Oct 16, 2019

    @JoeCodeswell
    Author

    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:

    
       User belongs to experiment group 'AlwaysDisplayTestExplorer - control'
       User belongs to experiment group 'ShowPlayIcon - start'
       User belongs to experiment group 'ShowExtensionSurveyPrompt - control'
       User belongs to experiment group 'AA_testing - experiment'
       > conda --version
       > pyenv root
       > python3.7 -c "import sys;print(sys.executable)"
       > python3.6 -c "import sys;print(sys.executable)"
       > python3 -c "import sys;print(sys.executable)"
       > python2 -c "import sys;print(sys.executable)"
       > python -c "import sys;print(sys.executable)"
       > py -3.7 -c "import sys;print(sys.executable)"
       > py -3.6 -c "import sys;print(sys.executable)"
       > py -3 -c "import sys;print(sys.executable)"
       > py -2 -c "import sys;print(sys.executable)"
       > python -c "import sys;print(sys.executable)"
       > conda info --json
       Starting Microsoft Python language server.
       > C:\Python27\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
       > C:\Python27\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
       > C:\cygwin64\bin\python2.7.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
       > C:\cygwin64\bin\python2.7.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
       > C:\Program Files (x86)\LilyPond\usr\bin\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
       > C:\Program Files (x86)\LilyPond\usr\bin\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
       > C:\Program Files (x86)\LilyPond\usr\bin\python2.4.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
       > C:\Program Files (x86)\LilyPond\usr\bin\python2.4.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
       > C:\Python27\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
       > C:\Python27\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
       > C:\Python27\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
       > C:\Python27\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
       > conda info --json
       > conda --version
    
    

    I hope this is what you wanted.
    Thanks again, Jake.
    Love and peace,
    Joe

  3. JoeCodeswell commented on Oct 16, 2019

    @JoeCodeswell
    Author

    I just did a second run of my program just to be sure. Here's Output.python again.

        User belongs to experiment group 'AlwaysDisplayTestExplorer - control'
        User belongs to experiment group 'ShowPlayIcon - start'
        User belongs to experiment group 'ShowExtensionSurveyPrompt - control'
        User belongs to experiment group 'AA_testing - experiment'
        > conda --version
        > pyenv root
        > python3.7 -c "import sys;print(sys.executable)"
        > python3.6 -c "import sys;print(sys.executable)"
        > python3 -c "import sys;print(sys.executable)"
        > python2 -c "import sys;print(sys.executable)"
        > python -c "import sys;print(sys.executable)"
        > py -3.7 -c "import sys;print(sys.executable)"
        > py -3.6 -c "import sys;print(sys.executable)"
        > py -3 -c "import sys;print(sys.executable)"
        > py -2 -c "import sys;print(sys.executable)"
        > python -c "import sys;print(sys.executable)"
        > conda info --json
        Starting Microsoft Python language server.
        > C:\Python27\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
        > C:\Python27\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
        > C:\cygwin64\bin\python2.7.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
        > C:\cygwin64\bin\python2.7.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
        > C:\Program Files (x86)\LilyPond\usr\bin\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
        > C:\Program Files (x86)\LilyPond\usr\bin\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
        > C:\Program Files (x86)\LilyPond\usr\bin\python2.4.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
        > C:\Program Files (x86)\LilyPond\usr\bin\python2.4.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
        > C:\Python27\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
        > C:\Python27\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
        > C:\Python27\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
        > C:\Python27\python.exe c:\Users\joeco\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
        > conda info --json
        > conda --version
    
    
    
  4. jakebailey commented on Oct 16, 2019

    @jakebailey
    Member

    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-issue

  5. JoeCodeswell commented on Oct 16, 2019

    @JoeCodeswell
    Author

    Hi Jake. Thanks for your patience. I just

    1. set "python.analysis.logLevel": "Trace" in File>>Preferences>>Settings.
    2. restarted vscode which NOW comes up with Update 1.39.2!
    3. checked settings & still "python.analysis.logLevel" == Trace

    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

  6. jakebailey commented on Oct 17, 2019

    @jakebailey
    Member

    Caching is disabled in those logs, so that's interesting.

    Reloading fixing it doesn't surprise me, as the analysis will have been rerun.

  7. sdpenguin commented on Oct 21, 2019

    @sdpenguin

    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.

  8. jakebailey commented on Oct 21, 2019

    @jakebailey
    Member

    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.

  9. pcolmer commented on Oct 22, 2019

    @pcolmer

    I'm having the same problem of "print" being marked as an undefined variable.

    Trace output attached.
    trace-logs.txt

  10. kuelumbus commented on Oct 22, 2019

    @kuelumbus

    I can confirm this problem. I am having it for all built-ins (dict, len, print, list, ...) ?

    image

    python.analysis.cachingLevel is set to None to fix #1601 .

  11. jakebailey commented on Oct 22, 2019

    @jakebailey
    Member

    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).

  12. kuelumbus commented on Oct 23, 2019

    @kuelumbus

    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.

  13. eerovil commented on Oct 24, 2019

    @eerovil

    I'm having the same problem, but reloading resolves it. For now I have to reload every hour or so.

  14. markedwards commented on Oct 25, 2019

    @markedwards

    This issue appears to affect many basic Python objects, like str. Attaching screenshot.
    Screenshot 2019-10-25 at 10 40 21

  15. jakebailey commented on Oct 25, 2019

    @jakebailey
    Member

    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.

  16. 31 remaining items

  17. kuelumbus commented on Nov 14, 2019

    @kuelumbus

    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.

    image

    image

    Trace log

  18. MikhailArkhipov commented on Nov 14, 2019

    @MikhailArkhipov

    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.
    

    way at the end. This is the root, IMO.

  19. kuelumbus commented on Nov 14, 2019

    @kuelumbus

    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.

  20. kuelumbus commented on Nov 16, 2019

    @kuelumbus

    Version 0.4.121 fixed it for me. However, I almost never see the doc string because it's constantly analyzing.

    log.log

  21. jakebailey commented on Nov 17, 2019

    @jakebailey
    Member

    Now it's stuck in a reload loop. Note:

    [Info  - 3:59:15 PM] Workspace root: /home/chris/data/ml/Net
    [Info  - 3:59:15 PM] GetCurrentSearchPaths /usr/bin/python3.7 
    [Info  - 3:59:15 PM] Interpreter search paths:
    [Info  - 3:59:15 PM]     /usr/lib/python3.7
    [Info  - 3:59:15 PM]     /usr/lib/python3.7/lib-dynload
    [Info  - 3:59:15 PM]     /home/chris/autocomplete
    [Info  - 3:59:15 PM]     /home/chris/.local/lib/python3.7/site-packages
    [Info  - 3:59:15 PM]     /data/chris/ml/Net
    [Info  - 3:59:15 PM]     /usr/local/lib/python3.7/dist-packages
    [Info  - 3:59:15 PM]     /usr/lib/python3/dist-packages
    

    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.

  22. kuelumbus commented on Nov 17, 2019

    @kuelumbus

    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?

  23. kuelumbus commented on Nov 17, 2019

    @kuelumbus

    Try setting "python.analysis.watchSearchPaths": false to disable file watching.

    resolved it. But also changing the workspace root to the direct path.
    Thanks for your help.

    [Info  - 8:12:55 PM] Workspace root: /data/chris/ml/Net
    [Info  - 8:12:55 PM] GetCurrentSearchPaths /usr/bin/python3.7 
    [Info  - 8:12:56 PM] Interpreter search paths:
    [Info  - 8:12:56 PM]     /usr/lib/python3.7
    [Info  - 8:12:56 PM]     /usr/lib/python3.7/lib-dynload
    [Info  - 8:12:56 PM]     /home/chris/autocomplete
    [Info  - 8:12:56 PM]     /home/chris/.local/lib/python3.7/site-packages
    [Info  - 8:12:56 PM]     /usr/local/lib/python3.7/dist-packages
    [Info  - 8:12:56 PM]     /usr/lib/python3/dist-packages
    
  24. MikhailArkhipov commented on Nov 17, 2019

    @MikhailArkhipov

    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

  25. michaelaye commented on Nov 17, 2019

    @michaelaye

    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.

  26. jakebailey commented on Nov 17, 2019

    @jakebailey
    Member

    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.

  27. jakebailey commented on Nov 17, 2019

    @jakebailey
    Member

    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.)

  28. MikhailArkhipov commented on Nov 18, 2019

    @MikhailArkhipov

    self issue is probably #1573

  29. juniorsaldanha commented on Oct 23, 2020

    @juniorsaldanha

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions