-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Suppress 'duplicate module named xx' errors? #4008
Comments
Those probably aren't packages, they're folders (or there are For this reason, implementing such a flag would not be easy, and probably not very useful. |
Hi @gvanrossum, I am writing a PyCharm/IntelliJ IDEA plugin to run mypy scanning and I am encountering the same issue. PyCharm/IntelliJ IDEA code inspection API sends me a list of open files in the IDE but, if the file list contains both a
Do you have any suggestion to scan both this files without running mypy separately for each of them? |
Would you like to contribute to existing one instead? https://github.com/dropbox/mypy-PyCharm-plugin |
Hi @ilevkivskyi, normally that would be the best thing to do, but I have already done adapting the code of my Pylint plugin to work with mypy. This plugin is based on Checkstyle-IDEA plugin and offers also real-time scanning, checkin validations and various on-demand scan actions. This is my latest build, is still not production ready but should give you an idea of what feature are there: Mypy-0.7.0.zip |
This is because apparently you seem to have both a folder named |
Oh ok, thanks for the clarification 👍. |
Hi @gvanrossum, I am now getting the same error when I try to check these files from mypy project:
or just simply these 2 files:
Is it also in this case a project problem? And why it does not happen when I scan the entire project using |
Presumably the folders containing the |
Hey @gvanrossum, thank you for your answer. You are correct, the folders don't have But unfortunately the option
|
I suggest asking for help in a more interactive forum, e.g.
https://gitter.im/python/typing
|
I have this problem frequently where I'm scanning separate packages with pre-commit hooks. It would be very useful to be able to disable this check completely, or else have an obvious workaround. Scripts-are-modules does not help. |
You'll have to write a script that scans the packages and produces a full list of files to pass to mypy except for the files you don't want. |
That's exactly when this problem occurs - when that full list of files contains 'duplicate modules named x'. (An example of the script that does that is |
Obviously that's a bug in your script, not in mypy. :-) |
I hit this again, but found a solution (for specifically the - id: mypy
name: mypy-one
files: ^one/
entry: mypy one/
pass_filenames: false
- id: mypy
name: mypy-two
files: ^two/
entry: mypy two/
pass_filenames: false
... and of course whatever Bit of a pain to have to maintain this - especially because if you add a (NB: Note that the |
Edit by hauntsaninja: I strongly recommend against disabling error code misc, putting in a dropdown so people don't copy it The "duplicate module" error is in the [mypy]
disable_error_code = misc
show_error_codes = True
files = **/*.py For the pre-commit case mentioned above (#4008 (comment), also see https://github.com/pre-commit/mirrors-mypy/issues/5), try using pre-commit/mirrors-mypy with
# .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.790
hooks:
- id: mypy
language: system
pass_filenames: false |
You should not use @br3ndonland's |
Unless I'm mistaken, none of the workarounds allow to scan all the files in a monorepo, which has something like:
Scanning above-like monorepo from main level simply does not work now, as each component holds their "duplicate"
(And I'm not sure if I can even do this with Besides, what's the harm in having similarly named files in different directories? They are standalone Now that 0.800+ supports recursive file scanning, could this issue be re-considered? |
Opened #10428 to perhaps better describe (or ask about) the problem. |
Mypy now is severely confused by there being a bitbox02.py inside a bitbox02 folder, resulting in duplicate module errors. See python/mypy#4008. gvanrossum writes: > This is because apparently you seem to have both a folder named gsi and a file name gsi.py. This is a problem for Python too (IIRC the folder/package wins) so you can't really blame mypy for complaining about this. I don't understand this, as Python seems to handle it fine in our package, but mypy does not.
Mypy now is severely confused by there being a bitbox02.py inside a bitbox02 folder, resulting in duplicate module errors. See python/mypy#4008. gvanrossum writes: > This is because apparently you seem to have both a folder named gsi and a file name gsi.py. This is a problem for Python too (IIRC the folder/package wins) so you can't really blame mypy for complaining about this. I don't understand this, as Python seems to handle it fine in our package, but mypy does not.
- check subdirs separately (python/mypy#4008) - use mypy flags --install-types --non-interactive - fixup noxfile: use lint_plugins to run mypy on plugins - noxfile: run mypy on tools/ without --strict flag
@tuukkamustonen described the issue perfectly in terms of monorepo usage - I also don't find any of these workarounds to resolve the issue. |
To add another case where this breaks down, when authoring data pipelines in airflow it is common practice to name each pipeline |
`pre-commit` is known to override behavior from config files in certain instances. This commit fixes known issues for: - `isort` - `black` - `mypy` For relevant details, see: isort: + https://jugmac00.github.io/blog/isort-and-pre-commit-a-friendship-with-obstacles/ + PyCQA/isort#885 black: + psf/black#1584 mypy: + python/mypy#4008 (comment) + https://pre-commit.com/#hooks-pass_filenames
`pre-commit` is known to override behavior from config files in certain instances. This commit fixes known issues for: - `isort` - `black` - `mypy` - `pydocstyle` For relevant details, see: isort: + https://jugmac00.github.io/blog/isort-and-pre-commit-a-friendship-with-obstacles/ + PyCQA/isort#885 black: + psf/black#1584 mypy/pydocstyle: + python/mypy#4008 (comment) + https://pre-commit.com/#hooks-pass_filenames
* refactor(trove-classifiers): update to python 3.7-3.9 * refactor(linters): add `.flake8` and `.codespellrc` configuration files Also add `PullRequest` to `ignore_words.txt` * feat(pyproject): add `pyproject.toml` Currently, this is only use for configuring linters and formatters (no build file specifications are set). Configuration options for `black` and `pydocstyle` are added here in this commit. * feat(pre-commit): add pre-commit * fix(mypy): add `mypy` dependency to `environment.yml` This supports conda test/build environments. * feat(pylint): Update `.pylintrc` Make this match settings specififed in `Makefile`. * feat(test): align checks All checks are placed in appropriate config files. Test runner scripts point to these so that there exists a single source of truth for all configurations and that the tests performed across systems is the same. This may be adjusted, of course, if different settings must be used on a per-system basis. * feat(requirements): add `toml` This package supports reading `pyproject.toml`, which is required for some of our tests. * fix(pre-commit): fix file passing errors `pre-commit` is known to override behavior from config files in certain instances. This commit fixes known issues for: - `isort` - `black` - `mypy` - `pydocstyle` For relevant details, see: isort: + https://jugmac00.github.io/blog/isort-and-pre-commit-a-friendship-with-obstacles/ + PyCQA/isort#885 black: + psf/black#1584 mypy/pydocstyle: + python/mypy#4008 (comment) + https://pre-commit.com/#hooks-pass_filenames * feat(ignores): ignore specific linting errors Ignore linting errors in source code in this PR. The purpose of this PR is to update linting tools. A future PR will correct the errors. This is done to separate concerns. Co-authored-by: Hendry, Adam <adam.hendry@medtronic.com>
Can you use a github repo if specifying |
I agree with @tuukkamustonen and @jaklan This has already been said, but to reiterate: By default, Hence everytime Sometimes specifying The real issue has to do with |
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.
To those that are still looking for some solution for monorepo: - repo: local
hooks:
- id: mypy
name: mypy
entry: bash -c 'SUBREPO=$(echo "$@" | sed "s/\/.*//"); ABS_PATH="$PWD/$@"; cd $SUBREPO; mkdir -p .mypy_cache; mypy "$ABS_PATH" --install-types --non-interactive'
language: python
language_version: python3
types: [python]
Now mypy should have correct idea of what is going on. I did the same trick with I hope that some of you will find it useful. |
I could not move mypy to the project root (python/mypy#4008).
I could not move mypy to the project root (python/mypy#4008).
My solution was to add this option in the mypy configuration: [tool.mypy]
packages = ["package1", "package2"] |
Am I right in thinking it's not presently possible to ignore errors for having multiple (as the error should really say, rather than 'duplicate') modules with the same name?
I'm running mypy on files in a repo that contains multiple packages with some commonality among them; for example they each have a
src/wsgi.py
, which renders:Multiple modules named xx
--allow-same-name-modules
/allow_same_name_modules = True
or similar?The text was updated successfully, but these errors were encountered: