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

[flake8-simplify] - Fix syntax error in autofix (SIM114) #9704

Merged
merged 1 commit into from
Jan 30, 2024
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
[flake8-simplify] - Fix syntax error in autofix (SIM114)
  • Loading branch information
diceroll123 committed Jan 30, 2024
commit 22b0d713978f976a6dff73f853b1913982700c7c
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,8 @@ def func():

if a: b # here's a comment
elif c: b


if(x > 200): pass
elif(100 < x and x < 200 and 300 < y and y < 800):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,9 @@ fn merge_branches(
return Err(anyhow::anyhow!("Expected colon after test"));
};

let mut following_branch_tokenizer =
SimpleTokenizer::starts_at(following_branch.test.end(), locator.contents());

// Identify the colon (`:`) at the end of the following branch's test.
let Some(following_branch_colon) =
following_branch_tokenizer.find(|token| token.kind == SimpleTokenKind::Colon)
else {
return Err(anyhow::anyhow!("Expected colon after test"));
};

let main_edit = Edit::deletion(
locator.full_line_end(current_branch_colon.end()),
locator.full_line_end(following_branch_colon.end()),
locator.full_line_end(current_branch.end()),
locator.full_line_end(following_branch.end()),
);

// If the test isn't parenthesized, consider parenthesizing it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,13 @@ SIM114.py:144:1: SIM114 Combine `if` branches using logical `or` operator
|
= help: Combine `if` branches

SIM114.py:148:1: SIM114 Combine `if` branches using logical `or` operator
|
148 | / if(x > 200): pass
149 | | elif(100 < x and x < 200 and 300 < y and y < 800):
150 | | pass
| |________^ SIM114
|
= help: Combine `if` branches


Original file line number Diff line number Diff line change
Expand Up @@ -442,5 +442,26 @@ SIM114.py:144:1: SIM114 [*] Combine `if` branches using logical `or` operator
144 |-if a: b # here's a comment
145 |-elif c: b
144 |+if a or c: b # here's a comment
146 145 |
147 146 |
148 147 | if(x > 200): pass

SIM114.py:148:1: SIM114 [*] Combine `if` branches using logical `or` operator
|
148 | / if(x > 200): pass
149 | | elif(100 < x and x < 200 and 300 < y and y < 800):
150 | | pass
| |________^ SIM114
|
= help: Combine `if` branches

ℹ Safe fix
145 145 | elif c: b
146 146 |
147 147 |
148 |-if(x > 200): pass
149 |-elif(100 < x and x < 200 and 300 < y and y < 800):
150 |- pass
148 |+if(x > 200) or (100 < x and x < 200 and 300 < y and y < 800): pass


Loading