Skip to content

Commit

Permalink
Remove explicit casting to List when sorted() is applied (#12085)
Browse files Browse the repository at this point in the history
sorted() returns a sorted list.
sorted(list(A)) is equivalent to sorted(A) no matter A is Tuple, List, or Set

Ref: https://docs.python.org/3/library/functions.html#sorted
  • Loading branch information
XD-DENG authored Nov 4, 2020
1 parent d559da1 commit 7597f3a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,7 @@ def tree(self):
)
dag_runs = {dr.execution_date: alchemy_to_dict(dr) for dr in dag_runs}

dates = sorted(list(dag_runs.keys()))
dates = sorted(dag_runs.keys())
max_date = max(dates) if dates else None
min_date = min(dates) if dates else None

Expand Down Expand Up @@ -2143,7 +2143,7 @@ def duration(self, session=None):
y=scale_time_units(cumulative_y[task_id], cum_y_unit),
)

dates = sorted(list({ti.execution_date for ti in task_instances}))
dates = sorted({ti.execution_date for ti in task_instances})
max_date = max([ti.execution_date for ti in task_instances]) if dates else None

session.commit()
Expand Down Expand Up @@ -2215,7 +2215,7 @@ def tries(self, session=None):
chart.add_serie(name=task.task_id, x=x_points, y=y_points)

tis = dag.get_task_instances(start_date=min_date, end_date=base_date)
tries = sorted(list({ti.try_number for ti in tis}))
tries = sorted({ti.try_number for ti in tis})
max_date = max([ti.execution_date for ti in tis]) if tries else None
chart.create_y_axis('yAxis', format='.02f', custom_format=False, label='Tries')
chart.axislist['yAxis']['axisLabelDistance'] = '-15'
Expand Down Expand Up @@ -2299,7 +2299,7 @@ def landing_times(self, session=None):
)

tis = dag.get_task_instances(start_date=min_date, end_date=base_date)
dates = sorted(list({ti.execution_date for ti in tis}))
dates = sorted({ti.execution_date for ti in tis})
max_date = max([ti.execution_date for ti in tis]) if dates else None

session.commit()
Expand Down
2 changes: 1 addition & 1 deletion tests/build_provider_packages_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def insert_documentation(deps_dict: Dict[str, List[str]], res: List[str]):
print(f"Total: {len(errors)} errors.")
unique_sorted_dependencies: Dict[str, List[str]] = {}
for key in sorted(dependencies.keys()):
unique_sorted_dependencies[key] = sorted(list(set(dependencies[key])))
unique_sorted_dependencies[key] = sorted(set(dependencies[key]))
if provider_dependencies_file_name:
with open(provider_dependencies_file_name, "w") as providers_file:
json.dump(unique_sorted_dependencies, providers_file, indent=2)
Expand Down

0 comments on commit 7597f3a

Please sign in to comment.