From f5b28c0df8dd04b2e16c7588a7b33189ce2a1808 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 24 Jul 2025 19:14:22 +0500 Subject: [PATCH] util.get_work_schedule_tasks - fix critical bug with missing root tasks Now we also use generator to mirror get_schedule_cost_items --- .../ifcopenshell/util/sequence.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/sequence.py b/src/ifcopenshell-python/ifcopenshell/util/sequence.py index 44e5eaf0b0..babcfd6fbc 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/sequence.py +++ b/src/ifcopenshell-python/ifcopenshell/util/sequence.py @@ -21,7 +21,7 @@ import ifcopenshell.util.date from math import floor from functools import cache from typing import Union, Literal, Optional -from collections.abc import Iterator +from collections.abc import Generator DURATION_TYPE = Literal["ELAPSEDTIME", "WORKTIME", "NOTDEFINED"] @@ -289,18 +289,17 @@ def get_parent_task(task: ifcopenshell.entity_instance) -> Union[ifcopenshell.en return obj -def get_all_nested_tasks(task: ifcopenshell.entity_instance) -> Iterator[ifcopenshell.entity_instance]: +def get_all_nested_tasks(task: ifcopenshell.entity_instance) -> Generator[ifcopenshell.entity_instance]: for nested_task in get_nested_tasks(task): yield nested_task yield from get_all_nested_tasks(nested_task) -def get_work_schedule_tasks(work_schedule: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]: - tasks = [] +def get_work_schedule_tasks(work_schedule: ifcopenshell.entity_instance) -> Generator[ifcopenshell.entity_instance]: + """Get all work schedule tasks, including the nested ones.""" for root_task in get_root_tasks(work_schedule): - nested_tasks = get_all_nested_tasks(root_task) - tasks.extend(nested_tasks) - return tasks + yield root_task + yield from get_all_nested_tasks(root_task) def get_root_tasks(work_schedule: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]: