Skip to content

Intellisense doesn't respect __all__ when using import * #494

Closed

Description

Environment data

VS Code version: 1.19.1
Python Extension version: 0.9.1
Python Version: 3.6.0
OS and version: Win 10

Actual behavior

# A.py
import B
B. # intellisense shows foo and bar, but accessing bar would FAIL at runtime

# B.py
from C import *

# C.py
__all__ = ['foo']
foo = 42
bar = 24

Expected behavior

With the code above intellisense should only show foo.

Activity

  1. brettcannon commented on Jan 2, 2018

    @brettcannon
    Member

    We won't be changing this because (1) there are legitimate reasons to want to ignore __all__ and (2) use of import * outside of the REPL is generally discouraged in Python.

  2. letmaik commented on Jan 3, 2018

    @letmaik
    MemberAuthor

    I agree that it is generally discouraged but in certain situations it makes sense, for example within a library to expose members of internal modules within a single public facing module. Instead of explicitly importing each name of the internal modules, a star import is quite handy and it also serves for clearly defining what the public API is made out of.
    Apart from this, if someone trusts the intellisense and an __all__ is in play like in my example above, then the code will fail at runtime. I thought this should be a good reason to have a red squiggly line.

  3. brettcannon commented on Jan 3, 2018

    @brettcannon
    Member

    Squiggle underlines gets into linting which means we rely on Pylint, flake8, or whatever linter you choose to use. So if you want to be warned that you are using something not contained in __all__ then that falls under the purview of your chosen linter.

  4. letmaik commented on Jan 8, 2018

    @letmaik
    MemberAuthor

    I'm not sure if we're on the same page here. Ignore the squiggle lines for now. The main problem is that intellisense displays a lot more than what is actually possible to invoke. The members just do not exist and there will be a hard error at runtime. This is not about warnings or hiding private functions from novice users, it's about correctly computing the set of reachable symbols. Have a look at the example again to see what I mean.
    If this is still something not going to be fixed (IMO it's a bug since intellisense in that case let's you construct invalid code), would you accept a PR for it?

  5. brettcannon commented on Jan 8, 2018

    @brettcannon
    Member

    OK, now I see where you're coming from with your example. Sorry about the misunderstanding. 😄 I've re-opened this as an issue and I have confirmed this issue does exist.

  6. 8 remaining items

  7. removed this from the May 2018 milestone on Jun 6, 2018
  8. munael commented on Jan 25, 2019

    @munael

    Still an issue in the Microsoft Python Language Server.

    Python extension: 2018.12.1 (with the early/nightly updates setting set)
    VS Code: 1.31.0 (Insiders)

    Is there a more lively issue tracking this?

  9. brettcannon commented on Feb 15, 2019

    @brettcannon
    Member

    I can verify this isn't working in the language server v0.1.78.

    I've opened microsoft/python-language-server#619 to track this upstream.

  10. luabud commented on Sep 11, 2019

    @luabud
    Member

    Fixed upstream.

  11. locked as resolved and limited conversation to collaborators on Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-intellisenseLSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc.bugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions