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

Symbols defined in private modules and re-exported in public modules are auto-imported from private modules #6990

Open
rsokl opened this issue Feb 26, 2025 · 0 comments
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@rsokl
Copy link

rsokl commented Feb 26, 2025

Description

For a local project, when a symbol is defined in a private module (prefixed with _) and re-exported in a public module, Pylance's auto-import feature suggests importing from the private module instead of the public interface.

Reproduction Steps

Here's a minimal project structure to reproduce the issue:

my_package/
├── __init__.py
└── _private.py

With the following content:

my_package/_private.py

class MyClass:
    def hello(self):
        return "Hello from MyClass"

my_package/__init__.py

from .public import MyClass

__all__ = ["MyClass"]

Expected Behavior

When typing MyClass in a new file outside the package, Pylance should suggest:

from my_package import MyClass

Actual Behavior

Instead, Pylance suggests:

from my_package._private import MyClass

Environment

  • VS Code version: 1.97
  • Pylance version: 2025.2.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

3 participants