-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Ignore nitpick warnings with regular expressions using nitpick_ignore_regex
#9131
Conversation
Good point. So I think using regexp is better for this case. What do you think? |
Nice catch, I totally forgot about pointer/array types in C-like languages.
Hmm, I've thought about this a bit more, and it seems that even if we use regex for this (which we probably should), it would still break some existing uses of I see 3 possible solutions for this:
|
@tk0miya ping? Do you have a preference for any of the 3 options? |
For my self I have an ad-hoc extension where I define different kind of patterns to ignore. Getting rid of it and use build-in ignore functionality would be nice, and I think this PR might be enough. One thing which is not explicitly clear, but should be in the documentation in the end: is the regex matched directly, or with begin/end anchors? E.g., for a pattern |
+1 for the 1st idea.
Additionally, @shimizukawa also votes for the 1st idea. I talked with him at the Hack-a-thon event today.
I think it's better to match to the beginning of the types as |
So that would mean that |
Wait, it's not good to compare like
This should not match to |
Having it symmetric with respect to start and end anchors is probably easier to understand for those not used to the Python |
nitpick_ignore_regex
Thank you everyone for the feedback. I've implemented option 1 - Regarding how should the regular expression be matched, if I understood correctly, the 3 options were
My personal opinion is that the behaviour of My motivation for choosing
Just in case, I've added a description of this behaviour to the documentation and a separate unittest for it. |
Good point about |
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.
LGTM with nits.
As I commented above, I prefer the re.fullmatch()
approach in this case. +1 for this as updated.
@tk0miya have I addressed all of your comments? |
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.
Thank you for your work. LGTM!
Merged! |
Subject: Allow regex patterns in nitpick_ignore.
Edit: this PR originally proposed adding glob-like pattern matching, but after some discussion, it was changed to use regex patterns instead.
Feature or Bugfix
Purpose
Allow the user to specify regex patterns in the
nitpick_ignore
. Currently, the user is forced to enumerate all thenitpicks
that should be ignored, even if they follow a predictable pattern. So after some time, thenitpick_ignore
array might end up looking something like this:With this PR, the user can instead define
nitpick_ignore_regex = [(r'py:.*', r'foo\..*')]
.Compatibility
I reuse thesphinx.util.matching
mechanism to match glob patterns. To be completely honest, I am not 100% sure if it is okay to match thetype
andtarget
of the nitpick warnings like paths (i.e. are there any cases wheretype
ortarget
may contain the symbols/?[]^*
and not be a path). Based on the use cases ofnitpick_ignore
, that I've personally seen, I don't expect this to be an issue, but this is technically a breaking change if somebody is currently matching something like[woops]!
.Edit: no longer applicable, see further discussion in the comments.
Tests
I didn't find any tests for the current behaviour of
nitpick_ignore
, so I've implemented the tests both for the current behaviour and the new regex feature. I did this by finding existing tests, which already usenitpicky=True
andassert
that there should be some errors. I copied these tests, added thenitpick_ignore_regex
option andassert
ed that the errors are gone in that case.