-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
0.971: Namespace packages -> Source file found twice under different module names #13202
Comments
Thanks for reporting! I haven't yet tried to confirm, but do let me know if you have an example repro :-) |
OK I got something 🙂 Setup: pipx install pdm==1.15.4 # certainly possible to replicate with another build backend / project manager
mkdir repro-mypy
cd repro-mypy
cat <<EOF > pyproject.toml
[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"
[project]
name = "namespace-package"
description = "My namespace package."
version = "0.1.0"
readme = "README.md"
requires-python = ">=3.8"
[tool.pdm.build]
includes = ["src/namespace"]
[tool.pdm.dev-dependencies]
typing = ["mypy>=0.971"]
EOF
touch README.md
mkdir -p src/namespace/package
touch src/namespace/package/py.typed
echo "SOME_VAR: int = 0" > src/namespace/package/module.py
cat <<EOF > src/namespace/package/__init__.py
from namespace.package.module import SOME_VAR
__all__ = ["SOME_VAR"]
EOF
pdm install Repro: $ pdm run mypy src/ --verbose
LOG: Mypy Version: 0.971
LOG: Config File: Default
LOG: Configured Executable: /home/user/.basher-packages/pyenv/pyenv/versions/3.8.11/bin/python3
LOG: Current Executable: /home/user/.basher-packages/pyenv/pyenv/versions/3.8.11/bin/python3
LOG: Cache Dir: .mypy_cache
LOG: Compiled: True
LOG: Exclude: []
LOG: Found source: BuildSource(path='src/namespace/package/__init__.py', module='package', has_text=False, base_dir='/home/user/repro-mypy/src/namespace')
LOG: Found source: BuildSource(path='src/namespace/package/module.py', module='package.module', has_text=False, base_dir='/home/user/repro-mypy/src/namespace')
LOG: Could not load cache for package: package/__init__.meta.json
LOG: Metadata not found for package
LOG: Parsing src/namespace/package/__init__.py (package)
LOG: Metadata fresh for package.module: file src/namespace/package/module.py
LOG: Could not load cache for namespace.package.module: namespace/package/module.meta.json
LOG: Metadata not found for namespace.package.module
LOG: Parsing /home/user/repro-mypy/src/namespace/package/module.py (namespace.package.module)
LOG: Build finished in 0.009 seconds with 2 modules, and 1 errors
src/namespace/package/module.py: error: Source file found twice under different module names: "package.module" and "namespace.package.module"
Found 1 error in 1 file (errors prevented further checking) Have to go but will expand in the afternoon 🙂 |
Possibly not a bug but a change in behavior to be more strict. I'm able to work around the above issue with the following:
Ideally mypy would be able to understand that the root package is $ pdm run python
Python 3.8.11 (default, Jul 9 2021, 15:44:14)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print("\n".join(sys.path))
/home/user/.basher-packages/pyenv/pyenv/versions/3.8.11/lib/python38.zip
/home/user/.basher-packages/pyenv/pyenv/versions/3.8.11/lib/python3.8
/home/user/.basher-packages/pyenv/pyenv/versions/3.8.11/lib/python3.8/lib-dynload
/home/user/repro-mypy/__pypackages__/3.8/lib
/home/user/repro-mypy/src (emphasis on I think the workaround also means I have to run mypy several times with different options to be able to scan both my namespace package and other standalone scripts. |
Ah, the verbose mode actually outputs helpful hints 🙂
Didn't see those before 👍 |
Awesome, thank you for the thorough repro. Yeah, we include an example of running mypy with namespace packages in a src layout here: https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules
But the behaviour in this case has been this way for a while. I wasn't able to repro your example here #13202 (comment) . Specifically, I got the error on both 0.971 and 0.961 (and this is what I expected). Note that I wasn't able to run your repro exactly because Agreed that in general this could be more usable + your suggestion of using |
I've encountered a similar regression in handling of namespace packages going from 0.961 to 0.971, for which I can't find working mypy config/options: repro_v2.zip
The particular issue appears to be a bad interaction between:
Edit: fixed issue in repro |
Thanks, that's almost certainly a different issue: #13214 (comment) |
Unfortunately, there's no known workaround on 0.971 :-( I asked for a release with the fix here, but we'll see what happens: #13089 (comment) |
Can confirm master fixes the repro above and in our actual codebase. Thanks! |
Bug Report
With mypy 0.961 I was able to scan my namespace packages without any issue. I've just upgraded today to 0.971, and I'm now getting a
Source file found twice under different module names
error.To Reproduce
Create a namespace package and try to run mypy on it. I'll try to give an actual reproduction example tomorrow.
Expected Behavior
No "found twice" error.
Actual Behavior
"Found twice" error.
Your Environment
mypy.ini
(and other config files):Seems related to:
The text was updated successfully, but these errors were encountered: