Skip to content

Support package and module in config files #10728

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
akkornel opened this issue Jun 28, 2021 · 1 comment · Fixed by #13404
Closed

Support package and module in config files #10728

akkornel opened this issue Jun 28, 2021 · 1 comment · Fixed by #13404
Labels

Comments

@akkornel
Copy link

akkornel commented Jun 28, 2021

Feature

Allow listing modules/packages to check, within the MyPy config files.

Pitch

Today, it is possible to use the files config item (in mypy.ini, pyproject.toml, etc.) to tell MyPy what files to check. You can also do this on the command-line, by simply listing the files.

If you want MyPy to check an entire module or package, you can do so on the command line (with -m or -p), but there is no way to do this in a config file. Since it is possible to set files in config files, I think it should also be possible to set module and package. (I am suggesting not-plural names "module" and "package" to match the command-line arguments).

One question you might ask is "Why don't you just list the directory containing your modules/packages?" In my case, doing so gives me an error like this:

src/namespace1/namespace2/package1/file.py: error: Source file found twice under different module names: `package2` and `namespace1.namespace2.package2`

… or an error like this:

src/namespace1/namespace2/package1/__init.py__:NN: error: Skipping analyzing "namespace1": found module but no type hints of library stubs

All of my code is in the src directory. In my pyproject.toml, I have namespace_packages = true and mypy_path = ["src"]. The above error only happens if I try to specify a file or directory to check. If instead I use -p namespace1 (or -p namespace1.namespace2), everything is located, loaded, and typechecked successfully.

@hauntsaninja
Copy link
Collaborator

Reasonable feature request.
(Note for namespace package file listing, I think using --explicit-package-bases can solve that issue, see https://mypy.readthedocs.io/en/latest/running_mypy.html#mapping-file-paths-to-modules)

akkornel added a commit to stanford-rc/mais-apis-python that referenced this issue Jun 28, 2021
This switches to using MyPy's package-discovery mechanism, having it
enumerate and then type-check everything within and under
`stanford.mais`.

(`stanford.mais` is used instead of `stanford` in case anything else
starts using that namespace.)

This is better than listing a directory to check, because it ensures
that all modules have been discovered, and their relationships laid out.

Unfortunately, although it's possible to provide a list of
files/directories in config, you can't do this with modules/packages.
I've requested support for this in python/mypy#10728
hauntsaninja added a commit that referenced this issue Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants