Repository navigation
Closed
Closed
Copy link
Labels
bugmypy got something wrongmypy got something wrong
Description
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.
$ pdm run mypy src
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)
$ pdm run mypy src --namespace-packages
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)
$ pdm run mypy src --namespace-packages --explicit-package-bases
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)
$ pdm run mypy src/namespace
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)
$ pdm run mypy src/namespace --namespace-packages
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)
$ pdm run mypy src/namespace --namespace-packages --explicit-package-bases
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)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 version used: 0.971
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files):
[mypy]
ignore_missing_imports = true
show_error_codes = true
warn_unused_ignores = true
warn_unused_configs = true- Python version used: 3.8.11
- Operating system and version: Linux 3.10.0-862.6.3.el7.x86_64
Seems related to:
- "Source file found twice under different module names" with namespace package installed in virtualenv by "pip install -e ." #10172
- Mypy issue validating package with directory and -p arg #11234
- Support package and module in config files #10728
- ("unable to merge overloads" reported from site-packages #12162)
- (Namespace packages and __init__ imports #9716)
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong
Activity
hauntsaninja commentedon Jul 22, 2022
Thanks for reporting! I haven't yet tried to confirm, but do let me know if you have an example repro :-)
pawamoy commentedon Jul 22, 2022
OK I got something 🙂
Setup:
Repro:
Have to go but will expand in the afternoon 🙂
pawamoy commentedon Jul 22, 2022
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
namespace(notsrcnorpackage) thanks tosys.path, without the need forMYPYPATH=srcand--namespace-packages --explicit-package-bases:(emphasis on
/home/user/repro-mypy/srcbeing in sys.path)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.
pawamoy commentedon Jul 22, 2022
Ah, the verbose mode actually outputs helpful hints 🙂
Didn't see those before 👍
hauntsaninja commentedon Jul 23, 2022
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
pdmdidn't work for me (seemed to install x86 stuff on my m1 mac), so I did the editable install myself with pip.Agreed that in general this could be more usable + your suggestion of using
sys.pathto help out here is a good one. But that's a slightly different matter from addressing regressions between 0.961 and 0.971, which is typically more urgent. I'll continue to play around and see if I can find some behaviour that's regressed, but also curious for your thoughts. Also you've provided themypy -vlog of the failed run with 0.971, do you also have the logs from a successful run with 0.960?(Also fwiw, if there is a regression, I'm suspicious of #11143 )
edwardpeek-crown-public commentedon Aug 2, 2022
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
hauntsaninja commentedon Aug 2, 2022
Thanks, that's almost certainly a different issue: #13214 (comment)
I think I fixed the regression on master, could you confirm the fix?
python3 -m pip install -U git+https://github.com/python/mypy.gitto install latest codehauntsaninja commentedon Aug 2, 2022
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)
edwardpeek-crown-public commentedon Aug 2, 2022
Can confirm master fixes the repro above and in our actual codebase. Thanks!