From cf7aeae223acc5945e3ba2f3afc6c04b0623732d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= <6774676+eumiro@users.noreply.github.com> Date: Wed, 16 Aug 2023 20:37:45 +0200 Subject: [PATCH] Simplify conditions on len() in utils --- 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 4f9d37d0c901..c97e99aaba40 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 e07608030d42..63ca5da21946 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 9f7d5bc9373c..59c1d7980c1e 100644 --- a/airflow/utils/log/logging_mixin.py +++ b/airflow/utils/log/logging_mixin.py @@ -165,7 +165,7 @@ def write(self, message): 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 2ce279cb36b6..e957cce837fd 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 fd2d0f727ba1..167eb53b71ea 100644 --- a/airflow/utils/task_group.py +++ b/airflow/utils/task_group.py @@ -475,7 +475,7 @@ def topological_sort(self, _include_subdag_tasks: bool = False): 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.