From 1282f5c3089359e04d31eb6e9c21fa46fabe0967 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 4 Sep 2024 18:41:09 +0500 Subject: [PATCH] geom.Iterate - fix incorrect typing, document some arguments #5299 --- .../ifcopenshell/geom/main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/geom/main.py b/src/ifcopenshell-python/ifcopenshell/geom/main.py index 1952ea1e01..4b858bb891 100644 --- a/src/ifcopenshell-python/ifcopenshell/geom/main.py +++ b/src/ifcopenshell-python/ifcopenshell/geom/main.py @@ -437,6 +437,8 @@ def consume_iterator( break +# Overloads need to cover different return types +# based on `with_progress` argument. @overload def iterate( settings: settings, @@ -445,7 +447,7 @@ def iterate( include: Optional[Union[list[entity_instance], list[str]]] = None, exclude: Optional[Union[list[entity_instance], list[str]]] = None, with_progress: Literal[False] = False, - cache: Optional[serializers.hdf5] = None, + cache: Optional[str] = None, serializer_settings: Optional[serializer_settings] = None, geometry_library: GEOMETRY_LIBRARY = "opencascade", ) -> Generator[IteratorOutput, None, None]: ... @@ -457,7 +459,7 @@ def iterate( include: Optional[Union[list[entity_instance], list[str]]] = None, exclude: Optional[Union[list[entity_instance], list[str]]] = None, with_progress: Literal[True] = True, - cache: Optional[serializers.hdf5] = None, + cache: Optional[str] = None, serializer_settings: Optional[serializer_settings] = None, geometry_library: GEOMETRY_LIBRARY = "opencascade", ) -> Generator[tuple[int, IteratorOutput], None, None]: ... @@ -469,7 +471,7 @@ def iterate( include: Optional[Union[list[entity_instance], list[str]]] = None, exclude: Optional[Union[list[entity_instance], list[str]]] = None, with_progress: bool = False, - cache: Optional[serializers.hdf5] = None, + cache: Optional[str] = None, serializer_settings: Optional[serializer_settings] = None, geometry_library: GEOMETRY_LIBRARY = "opencascade", ) -> Generator[Union[IteratorOutput, tuple[int, IteratorOutput]], None, None]: ... @@ -480,12 +482,18 @@ def iterate( include: Optional[Union[list[entity_instance], list[str]]] = None, exclude: Optional[Union[list[entity_instance], list[str]]] = None, with_progress: bool = False, - cache: Optional[serializers.hdf5] = None, + cache: Optional[str] = None, serializer_settings: Optional[serializer_settings] = None, geometry_library: GEOMETRY_LIBRARY = "opencascade", ) -> Generator[Union[IteratorOutput, tuple[int, IteratorOutput]], None, None]: + """Get a geometry iterator for the provided file. + + :param cache: .h5 cache filepath (might not exist, will be created). + :param serializer_settings: Settings for cache serializer. Required if `cache` is provided. + """ it = iterator(settings, file_or_filename, num_threads, include, exclude, geometry_library) if cache: + assert serializer_settings, "`serializer_settings` argument is not optional if `cache` is provided." hdf5_cache = serializers.hdf5(cache, settings, serializer_settings) it.set_cache(hdf5_cache) yield from consume_iterator(it, with_progress=with_progress)