Skip to content
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

Support glob patterns when configuring mypy_path #9965

Open
gustavgransbo opened this issue Jan 25, 2021 · 3 comments
Open

Support glob patterns when configuring mypy_path #9965

gustavgransbo opened this issue Jan 25, 2021 · 3 comments
Labels
feature topic-configuration Configuration files and flags

Comments

@gustavgransbo
Copy link
Contributor

Feature

Support the glob patterns * and ** in the mypy_path configuration.

Should work the same way as it does for the files configuration.

Pitch
I have a monorepo, with a bunch of python libraries located in a directory called libs.
All packages are namespace packages with the same namespace, but they are kept in their own directory inside of the libs directory:

repository_root
│
└───libs
│   └───pkg-a
│   |    └───namespace
│   |
│   └───pkg-b
│   |    └───namespace
│   |
│   └───pkg-c
│        └───namespace
│
└───mypy.ini

The mypy_path declaration in my mypy.ini looks something like this (but with dozens of packages):

mypy_path = $MYPY_CONFIG_FILE_DIR/libs/pkg-a:
    $MYPY_CONFIG_FILE_DIR/libs/pkg-b:
    $MYPY_CONFIG_FILE_DIR/libs/pkg-c:

It would be very convenient to use a glob pattern like this instead:

mypy_path = $MYPY_CONFIG_FILE_DIR/libs/*

It's more concise, and would avoid potential problems with forgetting to include a newly added package in mypy_path.

Thanks for a great tool!

@gustavgransbo
Copy link
Contributor Author

I could have a go at implementing this, unless someone opposes the feature.

@AlexWaygood AlexWaygood added the topic-configuration Configuration files and flags label Apr 1, 2022
@DavidVujic
Copy link

This would be a great feature! I am trying to figure out how to set the mypy_path with a wildcard, to avoid specifying all paths, also a monorepo.

@DavidVujic
Copy link

DavidVujic commented Nov 16, 2022

I don't fully understand why, but mypy seems to recognize the packages when putting a py.typed file in the top namespace (such as in pkg-a in your example).

Do you think this is a good enough workaround until the feature would be added @gustavgransbo?

EDIT:
maybe I went a little bit too fast here. The code editor is happy, but when running the mypy cli I get a new set of errors such as ...Source file found twice under different module names...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature topic-configuration Configuration files and flags
Projects
None yet
Development

No branches or pull requests

3 participants