-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
reportMissingTypeStubs error when src directory isn't in extraPaths #4771
Comments
I'm not ale to repro the problem as reported. I've created the directory hierarchy and files as you've indicated. When I run
Do you happen to have a You said that you're seeing an error Also, if your project root is |
After some more testing I was able to narrow down the conditions that are causing this for me. Here's the setup that allows me to reproduce the issue (no higher level pyrightconfig anywhere):
module_a.py: from module_b import foo
foo() module_b.py: def foo():
pass pyproject.toml: [tool.pyright]
typeCheckingMode = "strict" The issue occurs when the When it is, I see a Output of
|
Any paths included If you don't want your |
Hello, I've the same problem, but here's my > (.venv) |> python -c "import sys; print('\n'.join(sys.path))"
C:\Users\us-er\AppData\Local\Programs\Python\Python38\python38.zip
C:\Users\us-er\AppData\Local\Programs\Python\Python38\DLLs
C:\Users\us-er\AppData\Local\Programs\Python\Python38\lib
C:\Users\us-er\AppData\Local\Programs\Python\Python38
C:\Users\us-er\Projects\pyvalidators\.venv
C:\Users\us-er\Projects\pyvalidators\.venv\lib\site-packages my project structure: > (.venv) |> tree .
pyvalidators/
├── .venv/
├── src/
│ ├── validators/
│ ├── __init__.py
│ ├── py.typed
│ ├── module_a.py
│ ├── module_b.py
│ ├── module_c.py
│ ├── .
│ ├── .
│ ├── .
│ └── module_z.py
├── tests/
│ └── test_module_a.py
│ ├── test_module_b.py
│ ├── test_module_c.py
│ ├── .
│ ├── .
│ ├── .
│ └── test_module_z.py
└── pyproject.toml and pyright configuration in [tool.pyright]
exclude = ["**/__pycache__", ".pytest_cache/", ".tox/", ".venv/", "site/"]
pythonVersion = "3.8"
pythonPlatform = "All"
typeCheckingMode = "strict"
As mentioned in the docs:
Aren't sub directories of Edit I think my problem is very much like: https://stackoverflow.com/questions/50155464/using-pytest-with-a-src-layer |
@joe733, I'm guessing that you're using the command-line version of pyright, as opposed to the language server. The language server supports a setting called "python.analysis.autoSearchPaths" which defaults to true. When this setting is enabled, it causes pyright to automatically add "src" as an extraPath. The problem is that the command-line (CLI) version of pyright doesn't support language server settings, so this internal setting wasn't enabled. I think it's reasonable to enable this by default for the CLI. The only downside is that there may be cases where users of the pyright CLI don't want "src" to be treated implicitly as an extraPath, but I think this will be rare. I've made this change, and it will be included in the next release of pyright. |
…nable "auto search paths", so it didn't automatically add "src" as an extra path. This addresses #4771.
I have a directory structure like so:
When I run
pyright src
fromproject_root
, I getreportMissingTypeStubs
errors for my modules. I read over this discussion and in that case the solution was to add the directory toextraPaths
so it could be resolved. But reading over the import resolution docs it seems like mysrc
folder should be resolved automatically:If no execution environment or extraPaths are configured, try to resolve using the local directory src
Setting
extraPaths = ["src"]
solves the issue, but I don't really understand why (seems like it might be a bug which is why I'm opening this issue).Separately, if it's intended that I have to set
extraPaths
like that, would it make sense for directories ininclude
to be effectively appended toextraPaths
under the hood? (or in other words directories ininclude
would be part of import resolution)For example:
include = ["some_dir"]
would automatically considersome_dir
during import resolution.Likewise, running
pyright some_dir
would do the same.I don't understand enough about how pyright works to know if that would cause issues though.
The text was updated successfully, but these errors were encountered: