Skip to content
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

mypy recurses into build directory and fails #18429

Closed
asarkar opened this issue Jan 7, 2025 · 2 comments
Closed

mypy recurses into build directory and fails #18429

asarkar opened this issue Jan 7, 2025 · 2 comments
Labels
bug mypy got something wrong

Comments

@asarkar
Copy link

asarkar commented Jan 7, 2025

Bug Report

I’ve a project structured as follows:

.
├── hello
│   ├── __init__.py
│   └── animal.py
├── tests
│   ├── __init__.py
│   └── test_animal.py
├── README
└── pyproject.toml

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:

[project.optional-dependencies]
test = [
    "pytest",
]
lint = [
    "ruff",
    "mypy",
]

[tool.mypy]
exclude = [
    'venv',
]
ignore_errors = false
warn_return_any = true
disallow_untyped_defs = true

The dependencies are installed as follows:

% ./venv/bin/python -m pip install --upgrade pip '.[test]' '.[lint]'

But my GitHub CI fails with the following error:

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.
  • Python version used: 3.13.1
@asarkar asarkar added the bug mypy got something wrong label Jan 7, 2025
@hauntsaninja
Copy link
Collaborator

Thanks, putting build in exclude will work, closing as a duplicate of #12505

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Jan 9, 2025
@asarkar
Copy link
Author

asarkar commented Jan 9, 2025

@hauntsaninja

putting build in exclude will work

As stated in this ticket:

The expectation from this ticket is to ignore the directories like venv and build by default without needing to be specified by the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants