-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add --exclude #9992
Add --exclude #9992
Conversation
Resolves python#4675, resolves python#9981 Additionally, we always ignore site-packages and node_modules. Also note that this doesn't really affect import discovery; it only directly affects passing files or packages to mypy. The additional check before suggesting "are you missing an __init__.py" didn't make any sense to me, so I removed it, appended to the message and downgraded the severity to note.
This comment has been minimized.
This comment has been minimized.
This shouldn't actually come up in practice, since we use absolute paths pretty aggressively.
mypy/test/test_find_sources.py
Outdated
("a2.b.f", "/pkg"), | ||
] | ||
|
||
options.ignore_path = ["b/c"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a test case I'm not sure about.
We could complicate the behaviour, so that paths with slashes in the beginning or middle are treated as fixed paths to ignore, as opposed to patterns. That is, if there's a slash at the beginning it's just an absolute path and we ignore it. If there's a slash in the middle, then we treat it as a fixed path relative to the current directory and ignore it.
As opposed to right now, where we just treat "b/c" as a suffix and use it to ignore "CWD/x/y/b/c" as well as "CWD/b/c"
There's a bikeshedding opportunity here for (re)naming --ignore-path :) Arbitrary survey of tools that I commonly use:
I find that he word "ignore" could also refer to scanning files and ignoring errors therein. Like the existing I would slightly prefer --exclude or --exclude-path, as there is less potential for this confusion. |
Sure, I'll also call out that many other tools support regexes or globs. We can do this too, but it's not critical and I figure it's something we could always choose to add support for later. |
Oh also I guess I never fully replied to #9981 (comment). |
I like I actually like how black does this, and I'd prefer to have something fairly similar. Here are some thoughts:
For example, the default pattern could be something like Other things that could be useful to ignore by default (and black ignores these):
|
Also, when using verbose logging ( |
Alternatively regex excludes could be a separate option (--exclude, --exclude-regex). But I have no preference on this matter. |
I think there are two paths here:
I would advocate for the former, as even though it would create some dirtier configs, it allows delivering something faster. Regex can be added as a separate option, as @intgr suggests. WDYT? |
I'd rather avoid the need for two options. We already have a large number of command-line options, and making sure all combinations of options work well is nontrivial. I think that it's also fine to turn off the new behavior (at least when not using |
I'm a bit late to the party, but for reference Black also got a feature request to support extending the default exclusions (psf/black#1571). I agree that for mypy it makes sense to default to extending the default excludes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates! Looks good, just a few small nits. I'll probably do the next mypy release next week (Mon, Tue or Wed), if everything goes as planned. If you don't have time to update the PR before that, I can do the minor tweaks myself.
Changes made! |
Diff from mypy_primer, showing the effect of this PR on open source code: xarray (https://github.com/pydata/xarray.git)
- conftest.py: error: Are you missing an __init__.py?
+ conftest.py: note: Are you missing an __init__.py? Alternatively, consider using --exclude to avoid checking one of them.
bandersnatch (https://github.com/pypa/bandersnatch.git)
+ src/bandersnatch/tests/plugins/test_allowlist_name.py: note: Are you missing an __init__.py? Alternatively, consider using --exclude to avoid checking one of them.
mitmproxy (https://github.com/mitmproxy/mitmproxy.git)
- examples/addons/anatomy.py: error: Are you missing an __init__.py?
+ examples/addons/anatomy.py: note: Are you missing an __init__.py? Alternatively, consider using --exclude to avoid checking one of them.
optuna (https://github.com/optuna/optuna.git)
+ examples/pruning/simple.py: note: Are you missing an __init__.py? Alternatively, consider using --exclude to avoid checking one of them.
ibis (https://github.com/ibis-project/ibis.git)
+ ibis/backends/hdf5/tests/conftest.py: note: Are you missing an __init__.py? Alternatively, consider using --exclude to avoid checking one of them.
|
Any idea when this get merged and released? mypy checks are broken for me since 0.800 and I need this option to fix this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates, looks great!
@MatthiasLohr I'm going to start to prepare the release now. It should be out today/tomorrow, assuming I encounter no unexpected issues. |
Resolves #4675, resolves #9981. Additionally, we always ignore site-packages and node_modules, and directories starting with a dot. Also note that this doesn't really affect import discovery; it only directly affects passing files or packages to mypy. The additional check before suggesting "are you missing an __init__.py" didn't make any sense to me, so I removed it, appended to the message and downgraded the severity to note. Co-authored-by: hauntsaninja <>
Awesome, thanks! |
I wanted to say (better late than never): thank you so much for implementing this capability on such short notice! Not only does this solve #9981, it almost halves the time taken for a full |
The way this option is implemented as a regex makes use of it in
Using Is this intentional, and if not should I open a new issue? |
The initial implementation didn't use regexes, but you can see Jukka's reasoning for regexes here: #9992 (comment) (tldr; matches how other tools do it, people are going to want it and it'd be a breaking change later) I'd open an issue for this. I think a good path forward here for making long regex's readable is allowing a list of regexes / the flag to be specified multiple times, and just chaining them together with "or"s. |
Resolves #4675, resolves #9981
Additionally, we always ignore site-packages and node_modules.
Also note that this doesn't really affect import discovery; it only
directly affects passing files or packages to mypy.
The additional check before suggesting "are you missing an
init.py" didn't make any sense to me, so I removed it, appended to
the message and downgraded the severity to note.