You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a project contains an untyped source (.py) file and a corresponding stub (.pyi) file, Mypy may emit "Duplicate module" errors depending on how the files were passed via the command line.
Consider a simple package foo with this project layout:
foo
├── __init__.py
└── __init__.pyi
Mypy runs without error if I pass it the foo directory as argument
$ mypy fooSuccess: no issues found in 1 source file
But if I pass the directory contents as separate arguments, Mypy emits an error due to the two files having the same module name
$ mypy foo/*foo/__init__.pyi: error: Duplicate module named "foo" (also at "foo/__init__.py")foo/__init__.pyi: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more infofoo/__init__.pyi: note: Common resolutions include: a) using `--exclude` to avoid checking one of them, b) adding `__init__.py` somewhere, c) using `--explicit-package-bases` or adjusting MYPYPATHFound 1 error in 1 file (errors prevented further checking)
Is this the intended behavior?
To Reproduce
(see above)
Expected Behavior
I expected that the .pyi file would supersede the .py file in both cases above (regardless of how the files were passed from the command line), or perhaps that Mypy would process the files independently in the second case and ignore naming collisions.
In my actual use case, I am running Mypy via a pre-commit hook, which always passes individual files as separate arguments. The addition of a stub file caused Mypy to raise the "Duplicate module" error. I was able to work around the error by configuring pre-commit to exclude the original .py file, but this seems like a pretty typical use case that Mypy might want to support.
Hello, I'm having the same issue here with my pre-commit hook. @gmgunter how did you manage to exclude your file ? It seems like my pre-commit hook is not picking up the args i'm giving.
Using command line works fine though.
mypy v1.11.2
Python 3.10.11
Mypy command-line flags: none
Mypy configuration options from mypy.ini (and other config files): none
Bug Report
When a project contains an untyped source (
.py
) file and a corresponding stub (.pyi
) file, Mypy may emit "Duplicate module" errors depending on how the files were passed via the command line.Consider a simple package
foo
with this project layout:Mypy runs without error if I pass it the
foo
directory as argumentBut if I pass the directory contents as separate arguments, Mypy emits an error due to the two files having the same module name
Is this the intended behavior?
To Reproduce
(see above)
Expected Behavior
I expected that the
.pyi
file would supersede the.py
file in both cases above (regardless of how the files were passed from the command line), or perhaps that Mypy would process the files independently in the second case and ignore naming collisions.In my actual use case, I am running Mypy via a pre-commit hook, which always passes individual files as separate arguments. The addition of a stub file caused Mypy to raise the "Duplicate module" error. I was able to work around the error by configuring pre-commit to exclude the original
.py
file, but this seems like a pretty typical use case that Mypy might want to support.isce-framework/snaphu-py#68
Actual Behavior
(see above)
Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: