IssueRaiser

Run without module detection logic

**Feature** Allow `mypy --no-module-detection` (or similar flag) to run without mypy attempting to map files as modules. For example, linting standalone scripts should not require module detection magic. **Pitch** Mypy has (somewhat confusing?) file-to-module mapping logic explained in https://mypy.readthedocs.io/en/latest/running_mypy.html#mapping-file-paths-to-modules. The key take away is that mypy attempts to determine a module name for each imported file (in various ways). For example, `a/b/c.py` -> `a.b.c`. However, the documentation doesn't give rationale for why this actually needs to be _always_ done. If you merely want to check standalone files like `mypy one.py` then why does this require determining module name for the file? (AFAIK, other linters like `pylint` don't have this kind of magic, perhaps because they don't follow imports like `mypy` does.) If we have two files `mypy one.py two.py` and `two` imports `one`, then the detection logic is needed, so that module `one` is found (and it's fine). However, if I have sub-directories with similarly named files, doing `mypy one/file.py two/file.py` throws: ``` two/file.py: error: Duplicate module named 'file' (also at 'one/file.py') ``` But these are two standalone files, in separate directories, not part of the same package. Why is the error there? Similar trouble is faced when maintaining a monorepo with multiple packages: ``` package1/ setup.py ... package2/ setup.py ... ``` Mypy will th

Posted by mtvx on May 6, 2021, 10:37 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments

onboarding (Other)

Run without module detection logic

mtvxMay 6, 2021, 10:37 AM

**Feature** Allow `mypy --no-module-detection` (or similar flag) to run without mypy attempting to map files as modules. For example, linting standalone scripts should not require module detection magic. **Pitch** Mypy has (somewhat confusing?) file-to-module mapping logic explained in https://mypy.readthedocs.io/en/latest/running_mypy.html#mapping-file-paths-to-modules. The key take away is that mypy attempts to determine a module name for each imported file (in various ways). For example, `a/b/c.py` -> `a.b.c`. However, the documentation doesn't give rationale for why this actually needs to be _always_ done. If you merely want to check standalone files like `mypy one.py` then why does this require determining module name for the file? (AFAIK, other linters like `pylint` don't have this kind of magic, perhaps because they don't follow imports like `mypy` does.) If we have two files `mypy one.py two.py` and `two` imports `one`, then the detection logic is needed, so that module `one` is found (and it's fine). However, if I have sub-directories with similarly named files, doing `mypy one/file.py two/file.py` throws: ``` two/file.py: error: Duplicate module named 'file' (also at 'one/file.py') ``` But these are two standalone files, in separate directories, not part of the same package. Why is the error there? Similar trouble is faced when maintaining a monorepo with multiple packages: ``` package1/ setup.py ... package2/ setup.py ... ``` Mypy will th

Comments (0)

No comments yet. Start the discussion.

Comment on this issue