Skip to content

Commit

Permalink
fixup! Support mutually exclusive branches for B031 (#3844) (#3875)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Apr 4, 2023
1 parent 10504eb commit 2b21eff
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
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 { .. }));

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

0 comments on commit 2b21eff

Please sign in to comment.