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

Add B034: re.sub/subn/split must pass flags/count/maxsplit as keyword arguments #398

Merged
merged 6 commits into from
Jul 10, 2023

Conversation

jakkdl
Copy link
Contributor

@jakkdl jakkdl commented Jul 1, 2023

Fixes #397

README.rst Outdated Show resolved Hide resolved
bugbear.py Outdated Show resolved Hide resolved
tests/test_bugbear.py Outdated Show resolved Hide resolved
@jakkdl jakkdl requested a review from JelleZijlstra July 3, 2023 11:40
Copy link
Collaborator

@cooperlees cooperlees left a 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.
Copy link
Collaborator

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.

Suggested change
**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.

Copy link
Contributor Author

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."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"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."

@jakkdl jakkdl requested a review from cooperlees July 10, 2023 10:58
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.

New check: re.sub[n]/re.split with regex flag as third argument w/o keyword
3 participants