From 4f3ba7ae228fcf0217e01b06b55607f460150225 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 14 Feb 2024 14:23:13 +0500 Subject: [PATCH] some typing --- .../ifcopenshell/api/project/append_asset.py | 3 ++- src/ifcopenshell-python/test/bootstrap.py | 4 ++-- src/ifcpatch/ifcpatch/recipes/ExtractElements.py | 9 +++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py b/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py index ae74cd3340..5a4aa71f34 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py +++ b/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py @@ -88,7 +88,8 @@ class Usecase: self.settings = {"library": library, "element": element} def execute(self): - self.added_elements = {} + # mapping of old element ids to new elements + self.added_elements:dict[int, ifcopenshell.entity_instance] = {} self.whitelisted_inverse_attributes = {} if self.settings["element"].is_a("IfcTypeProduct"): self.target_class = "IfcTypeProduct" diff --git a/src/ifcopenshell-python/test/bootstrap.py b/src/ifcopenshell-python/test/bootstrap.py index b87d30855b..93a713c3e6 100644 --- a/src/ifcopenshell-python/test/bootstrap.py +++ b/src/ifcopenshell-python/test/bootstrap.py @@ -25,7 +25,7 @@ import ifcopenshell.api.owner.settings class IFC4: @pytest.fixture(autouse=True) def setup(self): - self.file = ifcopenshell.api.run("project.create_file") + self.file:ifcopenshell.file = ifcopenshell.api.run("project.create_file") ifcopenshell.api.owner.settings.get_user = lambda ifc: (ifc.by_type("IfcPersonAndOrganization") or [None])[0] ifcopenshell.api.owner.settings.get_application = lambda ifc: (ifc.by_type("IfcApplication") or [None])[0] ifcopenshell.api.pre_listeners = {} @@ -35,7 +35,7 @@ class IFC4: class IFC2X3: @pytest.fixture(autouse=True) def setup(self): - self.file = ifcopenshell.api.run("project.create_file", version="IFC2X3") + self.file:ifcopenshell.file = ifcopenshell.api.run("project.create_file", version="IFC2X3") ifcopenshell.api.owner.settings.get_user = lambda ifc: ifc.createIfcPersonAndOrganization() ifcopenshell.api.owner.settings.get_application = lambda ifc: ifc.createIfcApplication() ifcopenshell.api.pre_listeners = {} diff --git a/src/ifcpatch/ifcpatch/recipes/ExtractElements.py b/src/ifcpatch/ifcpatch/recipes/ExtractElements.py index 94c2ec9450..d41bb8fa34 100644 --- a/src/ifcpatch/ifcpatch/recipes/ExtractElements.py +++ b/src/ifcpatch/ifcpatch/recipes/ExtractElements.py @@ -19,6 +19,7 @@ import ifcopenshell import ifcopenshell.api import ifcopenshell.util.selector +from typing import Union class Patcher: @@ -64,7 +65,7 @@ class Patcher: self.create_spatial_tree() self.file = self.new - def add_element(self, element): + def add_element(self, element) -> None: new_element = self.append_asset(element) if not new_element: return @@ -75,7 +76,7 @@ class Patcher: self.add_decomposition_parents(spatial_element, new_spatial_element) self.add_decomposition_parents(element, new_element) - def append_asset(self, element): + def append_asset(self, element) -> Union[ifcopenshell.entity_instance, None]: try: return self.new.by_guid(element.GlobalId) except: @@ -84,14 +85,14 @@ class Patcher: return self.new.add(element) return ifcopenshell.api.run("project.append_asset", self.new, library=self.file, element=element) - def add_decomposition_parents(self, element, new_element): + def add_decomposition_parents(self, element, new_element) -> None: for rel in element.Decomposes: parent = rel.RelatingObject new_parent = self.append_asset(parent) self.aggregates.setdefault(parent.GlobalId, set()).add(new_element) self.add_decomposition_parents(parent, new_parent) - def create_spatial_tree(self): + def create_spatial_tree(self) -> None: for relating_structure, related_elements in self.contained_ins.items(): self.new.createIfcRelContainedInSpatialStructure( ifcopenshell.guid.new(),