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

Stub files - Auto-import shown for already imported symbols #685

Closed
cdce8p opened this issue Dec 4, 2020 · 4 comments
Closed

Stub files - Auto-import shown for already imported symbols #685

cdce8p opened this issue Dec 4, 2020 · 4 comments
Assignees
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@cdce8p
Copy link

cdce8p commented Dec 4, 2020

Environment data

  • Language Server version: 2020.12.0
  • OS and version: macOS
  • Python version: 3.9

Expected behaviour

The Auto-import note should not be displayed for symbols which are already imported.

Actual behaviour

Screen Shot 2020-12-04 at 02 05 58

Code Snippet / Additional information

From my testing, this seem to affect only stub files.

from typing import Union

Union

--

Same example in a normal python file

Screen Shot 2020-12-04 at 02 18 06

@github-actions github-actions bot added the triage label Dec 4, 2020
@judej judej added the bug Something isn't working label Dec 7, 2020
@github-actions github-actions bot removed the triage label Dec 7, 2020
@heejaechang
Copy link
Contributor

@cdce8p can you give me more context/repro on this? creating blank a.py file and testing it doesn't repro it so it feels like it requires some setup to repro?

@cdce8p
Copy link
Author

cdce8p commented Mar 11, 2021

@heejaechang I can still reproduce the error with pylance 2021.3.1 in an empty project. However, as stated in the title and description, this only happens for stub files .pyi. Normal .py files are fine which I find a bit curious.

Here is what I did:

  1. Create a new folder
  2. Create a.pyi with
from typing import Union
  1. Start typing: Union in a new line and activate autocompletion

My folder settings:

{
    "python.languageServer": "Pylance",
    "python.analysis.typeCheckingMode": "strict",
}

@jakebailey
Copy link
Member

jakebailey commented Mar 11, 2021

I experienced this when I was working on the matplotlib stubs last week; I think the completion provider is using the wrong symbol table when offering completions within stubs, using the one that contains symbols externally visible to other files, and not the table that is internally visible to the stub itself.

In the above example, Union is not externally visible to importers of a.pyi. I bet if that line were changed to from typing import Union as Union (which is not the right thing to do except to test the theory), it'd work, as the Union symbol would appear to be externally visible.

@heejaechang heejaechang self-assigned this Mar 11, 2021
@jakebailey jakebailey added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Mar 15, 2021
@jakebailey
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 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