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

eladkal 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 a1e6cd411a Simplify conditions on `len()` in utils (#33567)
a1e6cd411a is described below

commit a1e6cd411af9a922a35d770fbe576d8e892f44e1
Author: Miroslav Šedivý <[email protected]>
AuthorDate: Mon Aug 21 06:27:33 2023 +0000

    Simplify conditions on `len()` in utils (#33567)
---
 airflow/utils/dates.py             | 2 +-
 airflow/utils/helpers.py           | 2 +-
 airflow/utils/log/logging_mixin.py | 2 +-
 airflow/utils/python_virtualenv.py | 8 ++++----
 airflow/utils/task_group.py        | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/airflow/utils/dates.py b/airflow/utils/dates.py
index 4f9d37d0c9..c97e99aaba 100644
--- a/airflow/utils/dates.py
+++ b/airflow/utils/dates.py
@@ -227,7 +227,7 @@ def infer_time_unit(time_seconds_arr: Collection[float]) -> 
TimeUnit:
 
     e.g. 5400 seconds => 'minutes', 36000 seconds => 'hours'
     """
-    if len(time_seconds_arr) == 0:
+    if not time_seconds_arr:
         return "hours"
     max_time_seconds = max(time_seconds_arr)
     if max_time_seconds <= 60 * 2:
diff --git a/airflow/utils/helpers.py b/airflow/utils/helpers.py
index e55a8e0044..baef1d3209 100644
--- a/airflow/utils/helpers.py
+++ b/airflow/utils/helpers.py
@@ -144,7 +144,7 @@ def chunks(items: list[T], chunk_size: int) -> 
Generator[list[T], None, None]:
 
 def reduce_in_chunks(fn: Callable[[S, list[T]], S], iterable: list[T], 
initializer: S, chunk_size: int = 0):
     """Split the list of items into chunks of a given size and pass each chunk 
through the reducer."""
-    if len(iterable) == 0:
+    if not iterable:
         return initializer
     if chunk_size == 0:
         chunk_size = len(iterable)
diff --git a/airflow/utils/log/logging_mixin.py 
b/airflow/utils/log/logging_mixin.py
index 9f7d5bc937..59c1d7980c 100644
--- a/airflow/utils/log/logging_mixin.py
+++ b/airflow/utils/log/logging_mixin.py
@@ -165,7 +165,7 @@ class StreamLogWriter(IOBase, IO[str]):  # type: 
ignore[misc]
     def flush(self):
         """Ensure all logging output has been flushed."""
         buf = self._buffer
-        if len(buf) > 0:
+        if buf:
             self._buffer = ""
             self._propagate_log(buf)
 
diff --git a/airflow/utils/python_virtualenv.py 
b/airflow/utils/python_virtualenv.py
index 2ce279cb36..e957cce837 100644
--- a/airflow/utils/python_virtualenv.py
+++ b/airflow/utils/python_virtualenv.py
@@ -53,12 +53,12 @@ def _generate_pip_install_cmd_from_list(
 
 
 def _generate_pip_conf(conf_file: Path, index_urls: list[str]) -> None:
-    if len(index_urls) == 0:
-        pip_conf_options = "no-index = true"
-    else:
+    if index_urls:
         pip_conf_options = f"index-url = {index_urls[0]}"
         if len(index_urls) > 1:
-            pip_conf_options += f"\nextra-index-url = {' 
'.join(index_urls[1:])}"
+            pip_conf_options += f"\nextra-index-url = {' '.join(x for x in 
index_urls[1:])}"
+    else:
+        pip_conf_options = "no-index = true"
     conf_file.write_text(f"[global]\n{pip_conf_options}")
 
 
diff --git a/airflow/utils/task_group.py b/airflow/utils/task_group.py
index fd2d0f727b..167eb53b71 100644
--- a/airflow/utils/task_group.py
+++ b/airflow/utils/task_group.py
@@ -475,7 +475,7 @@ class TaskGroup(DAGNode):
         graph_sorted: list[DAGNode] = []
 
         # special case
-        if len(self.children) == 0:
+        if not self.children:
             return graph_sorted
 
         # Run until the unsorted graph is empty.

Reply via email to