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

Pylance fails to recognice pkgutil.extend_path on src folders on "python.analysis.extraPaths" #5990

Closed
jdrese opened this issue Jun 11, 2024 · 1 comment
Assignees

Comments

@jdrese
Copy link

jdrese commented Jun 11, 2024

Environment data

  • Language Server version: Pylance language server 2024.6.1 (pyright version 1.1.364, commit 0618acc5) starting
  • OS and version: Windows 11
  • Python version (& distribution if applicable, e.g. Anaconda): virtualenv Python 3.10.8

Code Snippet

"python.analysis.extraPaths": [
     "..path/to/a/src/with/pkgutil.extend_path",
     "..path/to/another/src/extending_namespace" 
]

Repro Steps

  1. Create 2 different folder structures that will have a src folder and a python package name that is the same
  2. On the first python package init file add __path__ = pkgutil.extend_path(__path__, __name__)
  3. Add both python src folder to a workspace "python.analysis.extraPaths" to have auto complete and code intelissence
  4. Try importing python code from both of the folders. One of them will fail depending on the order of paths in "python.analysis.extraPaths"

Expected behavior

Pylance should be able to pick up that the python packages are extending the namespace

Actual behavior

Pylance fails to read content of one of the packages.

Extra note

The python.analisys.autoSearchPaths does work correctly and if you are withing a same workspace that has all the src folders within the space of the same root folder. Things work. But if another workspace is trying to "reference" code from another package it does not.

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Jun 11, 2024
@debonte
Copy link
Contributor

debonte commented Jun 13, 2024

Pyright (the type checker upon which Pylance is built), does not support dynamic modification of __path__. Here are several old Pyright issues discussing this that have some more detail:

If I misunderstood what you were asking for here, feel free to provide more detail and reopen the issue. In that case, a repo or zip file with a folder structure that reproduces the issue would be helpful.

@debonte debonte closed this as completed Jun 13, 2024
@debonte debonte added by design and removed needs repro Issue has not been reproduced yet labels Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants