This is an automated email from the ASF dual-hosted git repository.

husseinawala pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 6520653c43 Activate RUF015 that checks for unnecessary iterable 
allocation for first element (#38949)
6520653c43 is described below

commit 6520653c43e348e0ff0a9fab6ea4429451c0583c
Author: Hussein Awala <[email protected]>
AuthorDate: Sun Apr 14 21:53:01 2024 +0200

    Activate RUF015 that checks for unnecessary iterable allocation for first 
element (#38949)
---
 airflow/providers/amazon/aws/executors/ecs/ecs_executor.py | 2 +-
 dev/perf/scheduler_dag_execution_timing.py                 | 3 +--
 pyproject.toml                                             | 1 +
 tests/cli/commands/test_dag_command.py                     | 2 +-
 tests/utils/log/test_secrets_masker.py                     | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/airflow/providers/amazon/aws/executors/ecs/ecs_executor.py 
b/airflow/providers/amazon/aws/executors/ecs/ecs_executor.py
index aec7762d87..6730e57168 100644
--- a/airflow/providers/amazon/aws/executors/ecs/ecs_executor.py
+++ b/airflow/providers/amazon/aws/executors/ecs/ecs_executor.py
@@ -515,7 +515,7 @@ class AwsEcsExecutor(BaseExecutor):
                 task_descriptions = 
self.__describe_tasks(task_arns).get("tasks", [])
 
                 for task in task_descriptions:
-                    ti = [ti for ti in tis if ti.external_executor_id == 
task.task_arn][0]
+                    ti = next(ti for ti in tis if ti.external_executor_id == 
task.task_arn)
                     self.active_workers.add_task(
                         task,
                         ti.key,
diff --git a/dev/perf/scheduler_dag_execution_timing.py 
b/dev/perf/scheduler_dag_execution_timing.py
index 4006e74ae5..6c2019aaa5 100755
--- a/dev/perf/scheduler_dag_execution_timing.py
+++ b/dev/perf/scheduler_dag_execution_timing.py
@@ -79,8 +79,7 @@ class ShortCircuitExecutorMixin:
         if not run:
             import airflow.models
 
-            # odd `list()` is to work across Airflow versions.
-            run = list(airflow.models.DagRun.find(dag_id=dag_id, 
execution_date=execution_date))[0]
+            run = airflow.models.DagRun.find(dag_id=dag_id, 
execution_date=execution_date)[0]
             self.dags_to_watch[dag_id].runs[execution_date] = run
 
         if run and all(t.state == TaskInstanceState.SUCCESS for t in 
run.get_task_instances()):
diff --git a/pyproject.toml b/pyproject.toml
index 1bc89bbea8..0cf12cbe0c 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -293,6 +293,7 @@ extend-select = [
     "B028", # No explicit stacklevel keyword argument found
     "TRY002", # Prohibit use of `raise Exception`, use specific exceptions 
instead.
     "RUF006", # Checks for asyncio dangling task
+    "RUF015", # Checks for unnecessary iterable allocation for first element
 ]
 ignore = [
     "D203",
diff --git a/tests/cli/commands/test_dag_command.py 
b/tests/cli/commands/test_dag_command.py
index fb472fbdb0..ec382ef6d4 100644
--- a/tests/cli/commands/test_dag_command.py
+++ b/tests/cli/commands/test_dag_command.py
@@ -1023,4 +1023,4 @@ class TestCliDags:
             dr = dag.test()
             assert mock_run.call_args_list[0] == ((trigger,), {})
             tis = dr.get_task_instances()
-            assert [x for x in tis if x.task_id == "abc"][0].state == "success"
+            assert next(x for x in tis if x.task_id == "abc").state == 
"success"
diff --git a/tests/utils/log/test_secrets_masker.py 
b/tests/utils/log/test_secrets_masker.py
index 84170f962e..c5f9c184f2 100644
--- a/tests/utils/log/test_secrets_masker.py
+++ b/tests/utils/log/test_secrets_masker.py
@@ -339,7 +339,7 @@ class TestSecretsMasker:
         assert "TypeError" not in caplog.text
 
     def test_masking_quoted_strings_in_connection(self, logger, caplog):
-        secrets_masker = [fltr for fltr in logger.filters if isinstance(fltr, 
SecretsMasker)][0]
+        secrets_masker = next(fltr for fltr in logger.filters if 
isinstance(fltr, SecretsMasker))
         with patch("airflow.utils.log.secrets_masker._secrets_masker", 
return_value=secrets_masker):
             test_conn_attributes = dict(
                 conn_type="scheme",

Reply via email to