Skip to content

Commit 79340c0

Browse files
committed
[v3-1-test] Enable ruff PLW0120 rule (apache#57456)
(cherry picked from commit 944a9f5) Co-authored-by: Jens Scheffler <95105677+jscheffl@users.noreply.github.com>
1 parent 59d8710 commit 79340c0

12 files changed

Lines changed: 24 additions & 33 deletions

File tree

airflow-core/src/airflow/cli/commands/db_command.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ def _get_version_revision(version: str, revision_heads_map: dict[str, str] | Non
8181

8282
if current < wanted:
8383
return head
84-
else:
85-
return None
84+
return None
8685

8786

8887
def run_db_migrate_command(args, command, revision_heads_map: dict[str, str]):

airflow-core/src/airflow/configuration.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,8 +1717,7 @@ def _deprecated_value_is_set_in_config(
17171717
deprecated_section_array = config.items(section=deprecated_section, raw=True)
17181718
if any(key == deprecated_key for key, _ in deprecated_section_array):
17191719
return True
1720-
else:
1721-
return False
1720+
return False
17221721

17231722
@staticmethod
17241723
def _deprecated_variable_is_set(deprecated_section: str, deprecated_key: str) -> bool:

dev/breeze/src/airflow_breeze/utils/packages.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ def get_provider_id_from_path(file_path: Path) -> str | None:
185185
for providers_root_candidate in parent.parents:
186186
if providers_root_candidate.name == "providers":
187187
return parent.relative_to(providers_root_candidate).as_posix().replace("/", ".")
188-
else:
189-
return None
188+
return None
190189
return None
191190

192191

providers/amazon/src/airflow/providers/amazon/aws/hooks/batch_client.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,7 @@ def poll_job_status(self, job_id: str, match_status: list[str]) -> bool:
386386
)
387387
if job_status in match_status:
388388
return True
389-
else:
390-
raise AirflowException(f"AWS Batch job ({job_id}) status checks exceed max_retries")
389+
raise AirflowException(f"AWS Batch job ({job_id}) status checks exceed max_retries")
391390

392391
def get_job_description(self, job_id: str) -> dict:
393392
"""
@@ -426,10 +425,9 @@ def get_job_description(self, job_id: str) -> dict:
426425
"check Amazon Provider AWS Connection documentation for more details.",
427426
str(err),
428427
)
429-
else:
430-
raise AirflowException(
431-
f"AWS Batch job ({job_id}) description error: exceeded status_retries ({self.status_retries})"
432-
)
428+
raise AirflowException(
429+
f"AWS Batch job ({job_id}) description error: exceeded status_retries ({self.status_retries})"
430+
)
433431

434432
@staticmethod
435433
def parse_job_description(job_id: str, response: dict) -> dict:

providers/amazon/src/airflow/providers/amazon/aws/hooks/datasync.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,5 +319,4 @@ def wait_for_task_execution(self, task_execution_arn: str, max_iterations: int =
319319
else:
320320
raise AirflowException(f"Unknown status: {status}") # Should never happen
321321
time.sleep(self.wait_interval_seconds)
322-
else:
323-
raise AirflowTaskTimeout("Max iterations exceeded!")
322+
raise AirflowTaskTimeout("Max iterations exceeded!")

providers/elasticsearch/tests/unit/elasticsearch/log/elasticmock/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ def _normalize_hosts(hosts):
8383
h["url_prefix"] = parsed_url.path
8484

8585
out.append(h)
86-
else:
87-
out.append(host)
86+
out.append(host)
8887
return out
8988

9089

providers/google/src/airflow/providers/google/cloud/hooks/bigquery.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,15 +1802,14 @@ def _prepare_query_configuration(
18021802
"must be a dict with {'projectId':'', "
18031803
"'datasetId':'', 'tableId':''}"
18041804
)
1805-
else:
1806-
configuration["query"].update(
1807-
{
1808-
"allowLargeResults": allow_large_results,
1809-
"flattenResults": flatten_results,
1810-
"writeDisposition": write_disposition,
1811-
"createDisposition": create_disposition,
1812-
}
1813-
)
1805+
configuration["query"].update(
1806+
{
1807+
"allowLargeResults": allow_large_results,
1808+
"flattenResults": flatten_results,
1809+
"writeDisposition": write_disposition,
1810+
"createDisposition": create_disposition,
1811+
}
1812+
)
18141813

18151814
if (
18161815
"useLegacySql" in configuration["query"]

providers/google/src/airflow/providers/google/cloud/hooks/gcs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,7 @@ def download(
371371
num_max_attempts,
372372
)
373373
raise
374-
else:
375-
raise NotImplementedError # should not reach this, but makes mypy happy
374+
raise NotImplementedError # should not reach this, but makes mypy happy
376375

377376
def download_as_byte_array(
378377
self,

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,9 @@ extend-select = [
587587
"TID25", # flake8-tidy-imports rules
588588
"E", # pycodestyle rules
589589
"W", # pycodestyle rules
590+
# Warning (PLW) re-implemented in ruff from Pylint
591+
"PLW0120", # else clause on loop without a break statement; remove the else and dedent its contents
592+
"PLW0127", # Self-assignment of variable
590593
# Per rule enables
591594
"RUF006", # Checks for asyncio dangling task
592595
"RUF015", # Checks for unnecessary iterable allocation for first element

scripts/ci/prek/common_prek_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ def get_provider_id_from_path(file_path: Path) -> str | None:
317317
for providers_root_candidate in parent.parents:
318318
if providers_root_candidate.name == "providers":
319319
return parent.relative_to(providers_root_candidate).as_posix().replace("/", ".")
320-
else:
321-
return None
320+
return None
322321
return None
323322

324323

0 commit comments

Comments
 (0)