Use Python's built-in efficient collection processing methods instead of manual implementations. This reduces code complexity and improves performance by leveraging optimized implementations.
Use Python’s built-in efficient collection processing methods instead of manual implementations. This reduces code complexity and improves performance by leveraging optimized implementations.
Key practices:
Example transformations:
# Instead of multiple set operations:
t_dags = {task.dag for task in tasks if not isinstance(task, tuple)}
t_dags_2 = {item[0].dag for item in tasks if isinstance(item, tuple)}
task_dags = t_dags | t_dags_2
# Use list comprehension:
task_dags = {
task[0].dag if isinstance(task, tuple) else task.dag
for task in tasks
}
# Instead of sorting and indexing:
items.sort(key=lambda x: x.end_date, reverse=True)
last_item = items[0] if items else None
# Use max():
last_item = max(items, key=lambda x: x.end_date) if items else None
# Instead of multiple isinstance checks:
if isinstance(log, chain) or isinstance(log, GeneratorType):
...
# Use tuple of types:
if isinstance(log, (chain, GeneratorType)):
...
Enter the URL of a public GitHub repository