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 --exclude more than once on command line #11329

Merged
merged 1 commit into from
Oct 22, 2021

Conversation

nipunn1313
Copy link
Contributor

Description

Support --exclude more than once on command line

The result is an "OR" of all the patterns provided.
Should be fully backward compatible to existing folks.

Fixes #10310

Test Plan

Added tests for the new behavior to test_find_sources.py. Also did a quick manual test to make sure command line arguments are working ok.

@github-actions

This comment has been minimized.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, maybe config is parsing it as a string still?

@nipunn1313
Copy link
Contributor Author

Yep - when I add it to setup.cfg, it's parsing as (using ibis as an example)

[mypy]
exclude = versioneer.py

as

['v', 'e', 'r', 's', 'i', 'o', 'n', 'e', 'e', 'r', '.', 'p', 'y']

I added four integration tests that should help cover this case and fixed the issue.
Good on mypy_primer!!

@@ -197,9 +197,9 @@ section of the command line docs.

.. confval:: exclude

:type: regular expression
:type: comma-separated list of regular expressions
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this actually seems bad - because commas can appear in regular expressions. Perhaps we need another way to delimit multiple entries? Is there precedent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per #10310 (comment) - I opted to go for newline separated list of regexes and updated the docs

SS of updated docs
image

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 Author

Update command_line.rst doc screenshot
image

@nipunn1313
Copy link
Contributor Author

Hiya - wanted to check in w/ the maintainers on this one again (no rush - just want to make sure it wasn't forgotten)

@hauntsaninja hauntsaninja merged commit 01d6eb8 into python:master Oct 22, 2021
@hauntsaninja
Copy link
Collaborator

Thanks, this is great!

@nipunn1313 nipunn1313 deleted the multiple_exclude branch October 30, 2021 18:01
@cclauss
Copy link
Contributor

cclauss commented Nov 5, 2021

It would be awesome to get a release that contains this fix.

mawillcockson added a commit to mawillcockson/mypy that referenced this pull request Dec 14, 2021
python#11329 added support for nicer `exclude` lists

TOML has a built-in list syntax, and it would be nice to use that for specifying lists for the `exclude` option.

This change tries the ini-style first: if `exclude` is set to a multiline string, it will split that on newlines, otherwise it will assume it's a list.
mawillcockson added a commit to mawillcockson/mypy that referenced this pull request Dec 14, 2021
python#11329 added support for nicer `exclude` lists

TOML has a built-in list syntax, and it would be nice to use that for specifying lists for the `exclude` option.

This change tries the ini-style first: if `exclude` is set to a multiline string, it will split that on newlines, otherwise it will assume it's a list.
@callahad
Copy link

For anyone following along at home, this does not appear to have made it into today's release of mypy 0.920.

@posita
Copy link
Contributor

posita commented Dec 22, 2021

How do these get represented in pyproject.toml? Could this be related to #11825?

@@ -124,6 +124,7 @@ def check_follow_imports(choice: str) -> str:
'cache_dir': expand_path,
'python_executable': expand_path,
'strict': bool,
'exclude': lambda s: [p.strip() for p in s.split('\n') if p.strip()],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible root cause for #11825?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - seems likely. Good find. The config_parser uses very basic newlines to split apart different excludes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior is documented in the config_file.rst - about multiple patterns in a newline separated manner.

Didn't realize that multiline excludes like this were an old pattern
Suggestion on what to do to fix?

Copy link
Contributor

@posita posita Dec 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't realize that multiline excludes like this were an old pattern

To be fair, I don't know if that was ever official. It was more of a work-around that folks discovered because they (probably like you) were desperately seeking a fix for #10310.

config_parser.py is new to me, and I'm still trying to digest it. At a high level, I'm wondering if one can treat .toml files differently? It looks like there's a mechanism to do that, but I'm still trying to figure out if it's sufficient for what I have in mind, i.e., in a .toml file, if it's a string, just parse it as a single regex, but if it's an array, treat each item as its own regex? (Just thinking out loud here.)

Copy link
Contributor

@posita posita Dec 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking further, I think this might be as simple as appending the following here:

toml_config_types.update({
    # …
    'exclude': try_split,
})

UPDATE: Nope. No. That would still try to split strings along commas.

Dunno what testing looks like yet, though….

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I know you, you're probably ¾ done with a PR by now, but if you haven't started, I can take a stab….

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't started. Go for it!
Appreciate the compliment :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked at the details, but there's also this PR that was opened recently: #11746

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads-up @hauntsaninja! I don't think that one works. I'll comment there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#11828 is up. I commented on #11746.

posita added a commit to posita/mypy that referenced this pull request Jan 1, 2022
Partially reverts python#11329 (with respect to `.ini` documentation).
Modifies existing unit tests.

Fixes python#11830.
JukkaL pushed a commit that referenced this pull request Jan 4, 2022
Partially reverts #11329 (with respect to `.ini` documentation).
Modifies existing unit tests.

Fixes #11830.

Co-authored-by: Matthew W <matthew@willcockson.family>
JukkaL pushed a commit that referenced this pull request Jan 5, 2022
Partially reverts #11329 (with respect to `.ini` documentation).
Modifies existing unit tests.

Fixes #11830.

Co-authored-by: Matthew W <matthew@willcockson.family>
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this pull request Jan 20, 2022
The result is an "OR" of all the patterns provided.
Should be fully backward compatible to existing folks.

Fixes python#10310
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this pull request Jan 20, 2022
Partially reverts python#11329 (with respect to `.ini` documentation).
Modifies existing unit tests.

Fixes python#11830.

Co-authored-by: Matthew W <matthew@willcockson.family>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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