Skip to content

Commit 944a9f5

Browse files
authored
Enable ruff PLW0120 rule (apache#57456)
1 parent eaa6972 commit 944a9f5

File tree

12 files changed

+22
-33
lines changed

12 files changed

+22
-33
lines changed

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
@@ -1759,8 +1759,7 @@ def _deprecated_value_is_set_in_config(
17591759
deprecated_section_array = config.items(section=deprecated_section, raw=True)
17601760
if any(key == deprecated_key for key, _ in deprecated_section_array):
17611761
return True
1762-
else:
1763-
return False
1762+
return False
17641763

17651764
@staticmethod
17661765
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
@@ -1846,15 +1846,14 @@ def _prepare_query_configuration(
18461846
"must be a dict with {'projectId':'', "
18471847
"'datasetId':'', 'tableId':''}"
18481848
)
1849-
else:
1850-
configuration["query"].update(
1851-
{
1852-
"allowLargeResults": allow_large_results,
1853-
"flattenResults": flatten_results,
1854-
"writeDisposition": write_disposition,
1855-
"createDisposition": create_disposition,
1856-
}
1857-
)
1849+
configuration["query"].update(
1850+
{
1851+
"allowLargeResults": allow_large_results,
1852+
"flattenResults": flatten_results,
1853+
"writeDisposition": write_disposition,
1854+
"createDisposition": create_disposition,
1855+
}
1856+
)
18581857

18591858
if (
18601859
"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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ extend-select = [
592592
"W", # pycodestyle rules
593593
# Warning (PLW) re-implemented in ruff from Pylint
594594
"PLW0127", # Self-assignment of variable
595+
"PLW0120", # else clause on loop without a break statement; remove the else and dedent its contents
595596
# Per rule enables
596597
"RUF006", # Checks for asyncio dangling task
597598
"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)