Pylance-release: `from X import Y as Z` highlights `Y` as undefined with semantic highlighting enabled

Created on 16 Sep 2020  路  9Comments  路  Source: microsoft/pylance-release

Environment data

  • Language Server version: 2020.9.4

  • OS and version: Windows 10 19041
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8
  • Expected behaviour

    Importing dataframe from the popular 3rd party library Dask should not be flagged. The code works when running.

    Actual behaviour

    from dask import dataframe is flagged with reportUndefinedVariable

    image

    Logs


    Logs

    [0916/214947.337:ERROR:registration_protocol_win.cc(103)] CreateFile: The system cannot find the file specified. (0x2)
    [Info  - 21:49:47] Pylance language server 2020.9.4 (pyright 9983747f) starting
    [Info  - 21:49:47] Server root directory: c:\Users\styagev\.vscode\extensions\ms-python.vscode-pylance-2020.9.4\dist
    [Info  - 21:49:48] Background analysis(3) root directory: c:\Users\styagev\.vscode\extensions\ms-python.vscode-pylance-2020.9.4\dist
    [Info  - 21:49:48] Background analysis(3) started
    [Info  - 21:49:48] Background analysis(4) root directory: c:\Users\styagev\.vscode\extensions\ms-python.vscode-pylance-2020.9.4\dist
    [Info  - 21:49:48] Background analysis(4) started
    [Error - 21:49:49] stubPath typings is not a valid directory.
    [Error - 21:49:51] stubPath typings is not a valid directory.
    [Error - 21:49:52] stubPath typings is not a valid directory.
    [Error - 21:49:54] stubPath typings is not a valid directory.
    [Error - 21:49:56] stubPath typings is not a valid directory.
    

    bug fixed in next version

    Most helpful comment

    I've implemented a fix, and it will be in the next release of Pylance.

    All 9 comments

    @syagev, could you please send the logs from the output window? Also if you can also add a screenshot that would be helpful.

    Does dataframe work normally in the rest of file regardless of the message

    Updated the issue body. Sorry for missing those details.

    The import line itself runs well, and dataframe module specifically also.

    I should also note I'm pretty sure this is a regression from a previous version. I've been using PyLance on this codebase pretty much since it's first day, and that import was always there so I probably would have noticed it.

    To clarify, we're not asking if the code runs, but if you get completion for things inside of dataframe in your code.

    I'm guessing yes based on that screenshot, and this is a bug similar to #322. If you set this and reload, does the problem go away?

    {
        "[python]": {
            "editor.semanticHighlighting.enabled": false
        }
    }
    

    Ah. Yes, I'm getting completions for that module.

    And yes, adding that setting made the problem go away! Thanks ;)

    Thanks for checking. This seems like #322, then, though a different AST node is being processed.

    I got the same flagging with pyspark

    from pyspark.sql import functions as F
    

    "functions" is not definedPylance (reportUndefinedVariable)

    I've implemented a fix, and it will be in the next release of Pylance.

    Yep, just to add to the conversation...

    In a Django project, I get the same using this import:

    from django.contrib.auth import views as auth_views
    

    Ordinary Import

    2020-09-29_14-24-56

    Aliased Import

    2020-09-29_14-24-29

    Hovering over the squiggly line, it says: "views" is not definedPylance (reportUndefinedVariable)

    I'll assume by the label that this will be fixed upon next release. This is just in case anyone else comes up against this.

    This issue has been fixed in version 2020.9.7, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202097-30-september-2020

    Was this page helpful?
    0 / 5 - 0 ratings