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
{{ message }}
Repository navigation
mypy recurses into build directory and fails #18429
This is just a personal Python library, and doesn’t need to be published or distributed. The usage consists of running pytest and mypy from the root directory.
Among other things, the pyproject.toml contains the following sections:
hello/__init__.py: error: Duplicate module named "hello" (also at "./build/lib/hello/__init__.py")
hello/__init__.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
hello/__init__.py: 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 MYPYPATH
Found 1 error in 1 file (errors prevented further checking)
Error: Process completed with exit code 2.
To Reproduce
Create a project as shown above, and run the pip install command.
Expected Behavior
I found a pip ticket for this exact problem where pytest was confused by the presence of a build directory. Apparently, in-place builds were introduced in pip 20.1, and is now the default.
One of the suggestions in the ticket was to ignore the build directory. pytest seems to have caught up since it no longer fails with the error reported in the ticket. Surprisingly, mypy does't exclude the build directory automatically, and needs to be told explicitly.
[tool.mypy]
exclude = [
"venv",
"build",
]
The expectation from this ticket is to ignore the directories like venv and build by default without needing to be specified by the user. Better yet, use the .gitignore.
Actual Behavior
Shown above.
Your Environment
Mypy version used: 1.14.1
Mypy command-line flags: --strict .
Mypy configuration options from mypy.ini (and other config files): Shown above.
Activity
hauntsaninja commentedon Jan 9, 2025
Thanks, putting build in exclude will work, closing as a duplicate of #12505
asarkar commentedon Jan 9, 2025
@hauntsaninja
As stated in this ticket:
mypy exclude files from .gitignore
mypy exclude files from .gitignore