some typing

This commit is contained in:
Andrej730
2024-02-14 14:23:13 +05:00
parent 075b9e4775
commit f522e2beb7
3 changed files with 9 additions and 7 deletions
@@ -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"
+2 -2
View File
@@ -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 = {}
@@ -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(),