-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[pylint
] Add fix for useless-else-on-loop
(PLW0120
)
#9590
[pylint
] Add fix for useless-else-on-loop
(PLW0120
)
#9590
Conversation
d11e4a3
to
dee62b0
Compare
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLW0120 | 26 | 13 | 13 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+13 -13 violations, +0 -0 fixes in 2 projects; 41 projects unchanged)
apache/airflow (+11 -11 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --preview --select ALL
+ airflow/configuration.py:1640:9: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents - airflow/configuration.py:1640:9: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + airflow/providers/amazon/aws/hooks/batch_client.py:371:9: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents - airflow/providers/amazon/aws/hooks/batch_client.py:371:9: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + airflow/providers/amazon/aws/hooks/batch_client.py:409:9: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents - airflow/providers/amazon/aws/hooks/batch_client.py:409:9: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + airflow/providers/amazon/aws/hooks/datasync.py:318:9: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents - airflow/providers/amazon/aws/hooks/datasync.py:318:9: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + airflow/providers/google/cloud/hooks/bigquery.py:2237:17: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents - airflow/providers/google/cloud/hooks/bigquery.py:2237:17: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + airflow/providers/google/cloud/hooks/bigquery.py:3075:17: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents - airflow/providers/google/cloud/hooks/bigquery.py:3075:17: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + airflow/providers/google/cloud/hooks/gcs.py:357:9: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents - airflow/providers/google/cloud/hooks/gcs.py:357:9: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + airflow/providers/http/hooks/http.py:411:13: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents - airflow/providers/http/hooks/http.py:411:13: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + airflow/providers/jenkins/operators/jenkins_job_trigger.py:181:9: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents - airflow/providers/jenkins/operators/jenkins_job_trigger.py:181:9: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + scripts/in_container/run_generate_constraints.py:317:13: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents - scripts/in_container/run_generate_constraints.py:317:13: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + tests/providers/elasticsearch/log/elasticmock/__init__.py:85:5: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents - tests/providers/elasticsearch/log/elasticmock/__init__.py:85:5: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it
demisto/content (+2 -2 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --preview
+ Packs/Carbon_Black_Enterprise_Response/Scripts/CBLiveGetFile/CBLiveGetFile.py:142:1: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents - Packs/Carbon_Black_Enterprise_Response/Scripts/CBLiveGetFile/CBLiveGetFile.py:142:1: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + Packs/ThreatQ/Integrations/ThreatQ_v2/ThreatQ_v2.py:589:5: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents - Packs/ThreatQ/Integrations/ThreatQ_v2/ThreatQ_v2.py:589:5: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it
Changes by rule (1 rules affected)
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLW0120 | 26 | 13 | 13 | 0 | 0 |
bf09089
to
bfba477
Compare
pylint
] - add fix for useless-else-on-loop
/ PLW0120
pylint
] Add fix for useless-else-on-loop
(PLW0120
)
Thanks @diceroll123, these are great! I know I'm behind on these reviews but I will get to them over time. |
Thanks, and no rush! 😄 It's the weekend, take it easy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
pub(crate) fn useless_else_on_loop( | ||
checker: &mut Checker, | ||
/// Generate a [`Fix`] to remove the `else` clause from the given statement. | ||
fn remove_else( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the handling out to its own function so that it can return Result
and make all the error cases explicit (rather than using unwrap
, which panics on failure).
indented, | ||
locator.line_start(else_range.start()), | ||
locator.full_line_end(end.end()), | ||
))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simplified this a bit, but we now drop comments on the same line as the else:
. I think this is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diceroll123 - Did you feel strongly about preserving these? I can see why it might be useful, but the comments do get moved, right? Like:
else: # some comment
x = 1
y = 2
Was getting moved to:
x = 1
y = 2 # some comment
Which struct me as potentially-wrong.
For example, in this case:
def test_retain_comment():
"""Retain the comment within the `else` block"""
for j in range(10):
pass
else: # [useless-else-on-loop]
print("fat chance")
for j in range(10):
break
The comment was moved to after the break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Merging to keep things moving but happy to revisit.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No strong feelings either way! It's much simpler without preserving comments on the else line.
Summary
adds fix for
useless-else-on-loop
/PLW0120
.Test Plan
cargo test