Skip to content

Checking modules with the same name in different folders fails. #16392

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

Closed
jenstroeger opened this issue Nov 2, 2023 · 1 comment
Closed

Checking modules with the same name in different folders fails. #16392

jenstroeger opened this issue Nov 2, 2023 · 1 comment
Labels
bug mypy got something wrong

Comments

@jenstroeger
Copy link

The following is a simplification of pytest’s conftest.py scenario, but can be reproduced fairly simply — it boils down to checking files (modules) with the same name in different folders with a single mypy invocation:

(.venv) > mkdir test
(.venv) > mkdir test/foo
(.venv) > mkdir test/bar
(.venv) > touch test/foo/same.py
(.venv) > touch test/bar/same.py
(.venv) > mypy test/foo/same.py 
Success: no issues found in 1 source file
(.venv) > mypy test/bar/same.py 
Success: no issues found in 1 source file

However, checking both files together causes the following error:

(.venv) > mypy test/foo/same.py test/bar/same.py 
test/bar/same.py: error: Duplicate module named "same" (also at "test/foo/same.py")
test/bar/same.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
test/bar/same.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)
(.venv) > mypy test/
test/foo/same.py: error: Duplicate module named "same" (also at "test/bar/same.py")
test/foo/same.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
test/foo/same.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)

I don’t really want to add __init__.py files to turn these folders into (sub)packages, because they’re simply independent files.

To Reproduce

See above.

Expected Behavior

That mypy checks both files and succeeds.

Actual Behavior

Above error.

Your Environment

  • Mypy version used: mypy 1.6.1 (compiled: yes)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: Python 3.11.6 (main, Oct 2 2023, 17:45:58) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
@jenstroeger jenstroeger added the bug mypy got something wrong label Nov 2, 2023
@jenstroeger jenstroeger changed the title Check modules with the same name in different folders. Checking modules with the same name in different folders fails. Nov 2, 2023
@ilevkivskyi
Copy link
Member

Have you tried --explicit-package-bases as the error message says? Anyway, it is a duplicate of #10428 (even though I don't understand what that issue is about, most use cases should be covered by this flag).

@ilevkivskyi ilevkivskyi closed this as not planned Won't fix, can't repro, duplicate, stale Nov 2, 2023
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