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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixup! Support mutually exclusive branches for B031 (#3844) #3875

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/ruff/resources/test/fixtures/flake8_bugbear/B031.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ def collect_shop_items(shopper, items):
for shopper in shoppers:
collect_shop_items(shopper, section_items) # B031

for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
if _section == "greens":
collect_shop_items(shopper, section_items)
else:
collect_shop_items(shopper, section_items)
collect_shop_items(shopper, section_items) # B031

for _section, section_items in itertools.groupby(items, key=lambda p: p[1]):
# Mutually exclusive branches shouldn't trigger the warning
if _section == "greens":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,9 @@ where
self.counter_stack.last_mut().unwrap().push(0);
}

let has_else = !is_if_arm
&& orelse
.first()
.map_or(false, |expr| !matches!(expr.node, StmtKind::If { .. }));
let has_else = orelse
.first()
.map_or(false, |expr| !matches!(expr.node, StmtKind::If { .. }));
dhruvmanila marked this conversation as resolved.
Show resolved Hide resolved

self.parent_ifs.push(stmt);
if has_else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,23 @@ expression: diagnostics
fixable: false
location:
row: 86
column: 40
column: 36
end_location:
row: 86
column: 49
fix:
edits: []
parent: ~
- kind:
name: ReuseOfGroupbyGenerator
body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage"
suggestion: ~
fixable: false
location:
row: 93
column: 40
end_location:
row: 93
column: 53
fix:
edits: []
Expand All @@ -120,10 +134,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 88
row: 95
column: 40
end_location:
row: 88
row: 95
column: 53
fix:
edits: []
Expand All @@ -134,10 +148,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 90
row: 97
column: 40
end_location:
row: 90
row: 97
column: 53
fix:
edits: []
Expand All @@ -148,10 +162,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 91
row: 98
column: 36
end_location:
row: 91
row: 98
column: 49
fix:
edits: []
Expand All @@ -162,10 +176,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 98
row: 105
column: 48
end_location:
row: 98
row: 105
column: 61
fix:
edits: []
Expand All @@ -176,10 +190,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 104
row: 111
column: 32
end_location:
row: 104
row: 111
column: 45
fix:
edits: []
Expand All @@ -190,10 +204,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 113
row: 120
column: 48
end_location:
row: 113
row: 120
column: 61
fix:
edits: []
Expand All @@ -204,10 +218,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 115
row: 122
column: 48
end_location:
row: 115
row: 122
column: 61
fix:
edits: []
Expand All @@ -218,10 +232,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 118
row: 125
column: 40
end_location:
row: 118
row: 125
column: 53
fix:
edits: []
Expand All @@ -232,10 +246,10 @@ expression: diagnostics
suggestion: ~
fixable: false
location:
row: 122
row: 129
column: 32
end_location:
row: 122
row: 129
column: 45
fix:
edits: []
Expand Down