-
Notifications
You must be signed in to change notification settings - Fork 881
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
pycodestyle
] Do not trigger E225
and E275
when the next token …
…is a ')' (#10315) ## Summary Fixes #10295. `E225` (`Missing whitespace around operator`) and `E275` (`Missing whitespace after keyword`) try to add a white space even when the next character is a `)` (which is a syntax error in most cases, the exceptions already being handled). This causes `E202` (`Whitespace before close bracket`) to try to remove the added whitespace, resulting in an infinite loop when `E225`/`E275` re-add it. This PR adds an exception in `E225` and `E275` to not trigger in case the next token is a `)`. It is a bit simplistic, but it solves the example given in the issue without introducing a change in behavior (according to the fixtures). ## Test Plan `cargo test` and the `ruff-ecosystem` check were used to check that the PR's changes do not have side-effects. A new fixture was added to check that running the 3 rules on the example given in the issue does not cause ruff to fail to converge.
- Loading branch information
1 parent
bc693ea
commit 8d73866
Showing
5 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
crates/ruff_linter/resources/test/fixtures/pycodestyle/E2_syntax_error.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a = (1 or) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...shots/ruff_linter__rules__pycodestyle__tests__white_space_syntax_error_compatibility.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs | ||
--- | ||
|