-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Run without module detection logic #10428
Comments
Does using |
I'm not using namespace packages so no. And mypy nags about duplicate modules Even with |
I'm having the same issue. I'm working with a mono repo with multiple packages and getting duplicate module errors because of the same situation as your example above with the 2 setup.py's. Have you found a workaround or a way to scan these separately in the config file? |
You could try |
Not sure if my earlier paste is a typo or if I actually misused |
My team has a case where we are using python scripts to generate a large, relatively-complex configuration tree. The directory structure and directory names of these scripts is a meaningful part of the configuration tree and that includes spaces in the directory names (ruling out making these directories in to packages without significant overhaul). Some of the scripts also have meaningful names, e.g. Maybe we can pass the list of files in each directory to a separate call of I feel a new flag, e.g. |
I've faced mypy's "duplicate module" issue in a number of source bases, and I haven't found a good workaround short of renaming modules or telling mypy to ignore parts of the code base. I agree that a new mode would be really useful here. I'm not clear on why this limitation exists in the first place, since it's legal for a code base to have duplicate module names as long as they don't result in a namespace conflict. Perhaps someone who is familiar with the inner workings of mypy could explain why this check exists? For what it's worth, pyright doesn't have this limitation, so it might suit your needs. |
Interesting. Thanks for your input, though I would have appreciated disclosure that you are the author of Pyright ;) We tried Pyright out, and it was indeed able to typecheck parts of the codebase which mypy refused to check due to the issue in this thread. It's certainly strange adding Node as a development dependency to our project, on the flipside. |
We tried out PyType because we liked that it could be installed with Python ecosystem tooling (pip), but it had the same problem with "duplicate" modules. We landed on running mypy in 3 phases:
Now our entire project is being typechecked again! But we have to deal with dozens of runs of mypy. We would really like to achieve this in one run with a flag like Here's the monstrosity if you'd like to adapt it to your project: |
Hi all, Please, check if this contribution (#12496) could help you. |
I just literally did what mypy suggested and it worked:
then
tried this on recent commit from master branch. |
I had the same problem with a monorepo.. Fortunately ChatGPT came to the rescue my structure:
I added an |
Running mypy on the whole repo generates errors when two folders contain two python files with the same name. This generates a mypy error and a simple solution to it is not possible. See related issues: - python/mypy#10428 - python/mypy#4008 For this reason, we restrict type checking only on the main package code.
Running mypy on the whole repo generates errors when two folders contain two python files with the same name. This generates a mypy error and a simple solution to it is not possible. See related issues: - python/mypy#10428 - python/mypy#4008 For this reason, we restrict type checking only on the main package code.
Running mypy on the whole repo generates errors when two folders contain two python files with the same name. This generates a mypy error and a simple solution to it is not possible. See related issues: - python/mypy#10428 - python/mypy#4008 For this reason, we restrict type checking only on the main package code.
Running mypy on the whole repo generates errors when two folders contain two python files with the same name. This generates a mypy error and a simple solution to it is not possible. See related issues: - python/mypy#10428 - python/mypy#4008 For this reason, we restrict type checking only on the main package code.
Running mypy on the whole repo generates errors when two folders contain two python files with the same name. This generates a mypy error and a simple solution to it is not possible. See related issues: - python/mypy#10428 - python/mypy#4008 For this reason, we restrict type checking only on the main package code.
Running mypy on the whole repo generates errors when two folders contain two python files with the same name. This generates a mypy error and a simple solution to it is not possible. See related issues: - python/mypy#10428 - python/mypy#4008 For this reason, we restrict type checking only on the main package code.
Running mypy on the whole repo generates errors when two folders contain two python files with the same name. This generates a mypy error and a simple solution to it is not possible. See related issues: - python/mypy#10428 - python/mypy#4008 For this reason, we restrict type checking only on the main package code.
Running mypy on the whole repo generates errors when two folders contain two python files with the same name. This generates a mypy error and a simple solution to it is not possible. See related issues: - python/mypy#10428 - python/mypy#4008 For this reason, we restrict type checking only on the main package code.
I solved this by running multiple mypy checks on my make recipe.
|
I have a project with a
All the source files are in When I run However, when I run
Even This is really frustrating, because it breaks VSCode's ability to run mypy. |
@MetRonnie Thanks, this explains why our CI pipeline stalls with Mypy. Our CI tooling provides a list of Python source file paths, but Mypy seems to (partially) scan other directories than just descendants of ( |
@MetRonnie Could you clarify what behavior you're expecting here? The docs for
which means that if you run |
I have no particular expectations, all I'm saying is the way See microsoft/vscode-mypy#157 (comment):
|
Same issue here, using pantsbuild to run mypy on a monorepo. There are conftest.py files in several submodules, and mypy fails with
|
I observe this still in 2024, and this directly contradicts what is documented in Bullet point 3 of https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules , so I consider this an implementation bug. |
The current version is buggy. See python/mypy#10428.
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 likemypy
does.)If we have two files
mypy one.py two.py
andtwo
importsone
, then the detection logic is needed, so that moduleone
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: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:
Mypy will throw error about duplicate module name on
setup.py
files (and others).Now, without arguing on how mypy should determine module name of the files is looks up (surely there's reasoning for that), I'm suggesting to add an option to completely skip this magic. In my case, I always
pip install -e .
the packages that I'm developing, so whatever imports the code (wherever), those imports are already resolvable. All the packages are already importable and whatever files reside out of the packages, are stand-alone scripts and never imported.One downside is that something like this would no longer work:
For that I don't have suggestion :( Could it be solved by multiple entries in
MYPYPATH
orPYTHONPATH
?The text was updated successfully, but these errors were encountered: