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

exclude key in mypy.ini as a single regex doesn't scale for larger code bases #10310

Closed
rgommers opened this issue Apr 11, 2021 · 5 comments · Fixed by #11329
Closed

exclude key in mypy.ini as a single regex doesn't scale for larger code bases #10310

rgommers opened this issue Apr 11, 2021 · 5 comments · Fixed by #11329
Assignees
Labels

Comments

@rgommers
Copy link

Feature

I'd like the exclude = in mypy.ini to have a saner way to specify a lot of paths that one huge one-line regex.

This is a follow-up to #9992 (comment)

When trying to use exclude (necessary because mypy 0.800 became much more aggressive in including paths by default) I ended up with something like:

files =
    torch,
    caffe2,
    test/test_bundled_images.py,
    test/test_bundled_inputs.py,
    test/test_complex.py,
    ... <many more paths here>

#
# `exclude` is a regex, not a list of paths like `files` (sigh)
#
exclude = torch/include/|torch/csrc/|torch/distributed/elastic/agent/server/api.py

Both the files and exclude list are likely to grow over time. I don't have a strong preference on how exclude should work exactly, any pattern that allows breaking the regex into one line per pattern will be fine. E.g.:

exclude =
    pattern1|
    pattern2|
    pattern3|

Using | or some character other than a comma to indicate that it does not work like files = seems like a good idea.

@samestep
Copy link

See also pytorch/pytorch#57967 (comment) for more context.

@ethanhs
Copy link
Collaborator

ethanhs commented Aug 1, 2021

In #10903 I think we decided that allowing to specify --exclude multiple times would be a good compromise. In the config file this would look like:

exclude =
    pattern1
    pattern2

which would be equivalent to:

exclude =
    pattern1|pattern2

@cclauss
Copy link
Contributor

cclauss commented Aug 2, 2021

Most Python practitioners know that pytest allows multiple --ignore options (strings) which are different from --ignore-glob options which support Unix shell-style wildcards. While it is probably too late for mypy to adopt this approach, it would have been the least surprising to newcomers. Also see, glob strings of flake8 --exclude and --extend-exclude.

Many people are not regex masters and regex syntax can be unintuitive for the uninitiated. Supporting both regex patterns ORed together with | as well as path string patterns separated by commas (or multiple --exclude statements) would provide a better user experience for a broader audience.

nipunn1313 added a commit to nipunn1313/mypy that referenced this issue Oct 13, 2021
The result is an "OR" of all the patterns provided.
Should be fully backward compatible to existing folks.

Fixes python#10310
nipunn1313 added a commit to nipunn1313/mypy that referenced this issue Oct 13, 2021
The result is an "OR" of all the patterns provided.
Should be fully backward compatible to existing folks.

Fixes python#10310
@nipunn1313
Copy link
Contributor

Assign this to me! I worked on it with #11329

@JelleZijlstra
Copy link
Member

Done, thanks @nipunn1313!

nipunn1313 added a commit to nipunn1313/mypy that referenced this issue Oct 14, 2021
The result is an "OR" of all the patterns provided.
Should be fully backward compatible to existing folks.

Fixes python#10310
nipunn1313 added a commit to nipunn1313/mypy that referenced this issue Oct 14, 2021
The result is an "OR" of all the patterns provided.
Should be fully backward compatible to existing folks.

Fixes python#10310
hauntsaninja pushed a commit that referenced this issue Oct 22, 2021
The result is an "OR" of all the patterns provided.
Should be fully backward compatible to existing folks.

Fixes #10310
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this issue Jan 20, 2022
The result is an "OR" of all the patterns provided.
Should be fully backward compatible to existing folks.

Fixes python#10310
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.

6 participants