-
Notifications
You must be signed in to change notification settings - Fork 109
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 B034: re.sub/subn/split must pass flags/count/maxsplit as keyword arguments #398
Conversation
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.
Let’s make readme and maybe the output message a little clearer on why we’re suggestion this change. I feel lots of bugbear users might be upset with this one if we don’t make the error messages as helpful as they could be.
README.rst
Outdated
@@ -188,6 +188,8 @@ second usage. Save the result to a list if the result is needed multiple times. | |||
|
|||
**B033**: Sets should not contain duplicate items. Duplicate items will be replaced with a single item at runtime. | |||
|
|||
**B034**: Calls to `re.sub`, `re.subn` or `re.split` should pass `flags` or `output`/`maxsplit` as keyword arguments. Not doing so is a very common source of confusion. |
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.
I had to go read the issue to understand what the confusion was here. Let’s try make this clearer to save people hunting the issue down.
**B034**: Calls to `re.sub`, `re.subn` or `re.split` should pass `flags` or `output`/`maxsplit` as keyword arguments. Not doing so is a very common source of confusion. | |
**B034**: Calls to `re.sub`, `re.subn` or `re.split` should pass `flags` or `output`/`maxsplit` as keyword arguments. Not doing so is a very common source of confusion due to the positions of these arguments differing in the `re` module APIs. |
- Happy for better wording.
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.
Isn't it just as much, if not more, about people not being aware that count
/maxsplit
are arguments at all, and just being used to passing flags
as the third argument to all the other functions in re
?
I agree with making it more clear though
bugbear.py
Outdated
@@ -1770,6 +1792,12 @@ def visit_Lambda(self, node): | |||
) | |||
) | |||
|
|||
B034 = Error( | |||
message=( | |||
"B034 {} should pass `{}` and `flags` as keyword arguments to avoid confusion." |
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.
"B034 {} should pass `{}` and `flags` as keyword arguments to avoid confusion." | |
"B034 {} should pass `{}` and `flags` as keyword arguments to avoid confusion due to different argument positions." |
Fixes #397