diff --git a/airflow/utils/dates.py b/airflow/utils/dates.py index 4f9d37d0c9018..c97e99aaba40b 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 e07608030d421..63ca5da219468 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 9f7d5bc9373cd..59c1d7980c1e3 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 2ce279cb36b64..e957cce837fdc 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 fd2d0f727ba14..167eb53b71eaa 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.