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

Typesheds shadow local modules when imported as from packageA import moduleB #6988

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

Comments

@GeorchW
Copy link

GeorchW commented Feb 26, 2025

When importing own modules that have the same name as other modules in the included typeshed fallbacks, the fallbacks are used instead of the local module under certain conditions, causing imports to fail for no apparent reason.

Environment data

  • Pylance version: 2025.2.1
  • OS and version: Ubuntu 24.04
  • Python version (& distribution if applicable, e.g. Anaconda): 3.13

Code Snippet

# main.py:
from import_export import import_export_module
import_export_module.say_hello()

# import_export/import_export_module.py:
def say_hello():
    print("Hello from import_export!")

Results in ""import_export_module" is unknown import symbol (reportAttributeAccessIssue)".

Ctrl+Clicking on "import_export" leads to ~/.vscode/extensions/ms-python.vscode-pylance-2025.2.1/dist/typeshed-fallback/stubs/django-import-export/import_export/__init__.pyi, showing that the language server resolved import_export to a typeshed module. However, this module is not installed and doesn't really clash with the local module definition.

It works when changing the code sligthly, e.g. using one of these imports instead:

import import_export.import_export_module
import import_export.import_export_module as import_export_module
from import_export.import_export_module import say_hello

But since there are a lot of modules for which typesheds exist, and that set is not constant, this isn't really a feasible workaround in general.

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Feb 26, 2025
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

2 participants