Skip to content

Commit

Permalink
Simplify conditions on len() in utils (#33567)
Browse files Browse the repository at this point in the history
  • Loading branch information
eumiro authored Aug 21, 2023
1 parent eb56473 commit a1e6cd4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion airflow/utils/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion airflow/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion airflow/utils/log/logging_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions airflow/utils/python_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")


Expand Down
2 changes: 1 addition & 1 deletion airflow/utils/task_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a1e6cd4

Please sign in to comment.