From bdbe91f0434da4056a0e08e3cab2405c8f9e1b0b Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 28 Oct 2024 11:23:35 +0500 Subject: [PATCH] typing --- src/bonsai/bonsai/bim/module/material/data.py | 4 ++-- src/bonsai/bonsai/bim/module/pset/prop.py | 2 +- .../api/georeference/edit_true_north.py | 1 + .../ifcopenshell/template.py | 24 ++++++++++--------- src/ifcsverchok/__init__.py | 5 ++-- src/ifcsverchok/ifcstore.py | 10 ++++---- 6 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/material/data.py b/src/bonsai/bonsai/bim/module/material/data.py index 69b62c2957..8eda7e3d72 100644 --- a/src/bonsai/bonsai/bim/module/material/data.py +++ b/src/bonsai/bonsai/bim/module/material/data.py @@ -24,7 +24,7 @@ import ifcopenshell.util.doc import ifcopenshell.util.schema import bonsai.tool as tool from bonsai.bim.module.drawing.helper import format_distance -from typing import Any +from typing import Any, Union def refresh(): @@ -174,7 +174,7 @@ class ObjectMaterialData: cls.is_loaded = True @classmethod - def material_class(cls): + def material_class(cls) -> Union[str, None]: element = tool.Ifc.get_entity(bpy.context.active_object) cls.material = ifcopenshell.util.element.get_material(element) if cls.material: diff --git a/src/bonsai/bonsai/bim/module/pset/prop.py b/src/bonsai/bonsai/bim/module/pset/prop.py index 02287097c6..263dd87288 100644 --- a/src/bonsai/bonsai/bim/module/pset/prop.py +++ b/src/bonsai/bonsai/bim/module/pset/prop.py @@ -52,7 +52,7 @@ def purge(): qtonames = {} -def blender_formatted_enum_from_psets(psets): +def blender_formatted_enum_from_psets(psets: list[ifcopenshell.entity_instance]) -> list[tuple[str, str, str]]: enum_items = [] version = tool.Ifc.get_schema() for pset in psets: diff --git a/src/ifcopenshell-python/ifcopenshell/api/georeference/edit_true_north.py b/src/ifcopenshell-python/ifcopenshell/api/georeference/edit_true_north.py index d4da8ecc3c..15a92c3598 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/georeference/edit_true_north.py +++ b/src/ifcopenshell-python/ifcopenshell/api/georeference/edit_true_north.py @@ -17,6 +17,7 @@ # along with IfcOpenShell. If not, see . import ifcopenshell +import ifcopenshell.util.element import ifcopenshell.util.geolocation from typing import Union, Optional diff --git a/src/ifcopenshell-python/ifcopenshell/template.py b/src/ifcopenshell-python/ifcopenshell/template.py index 13942431d4..0defb7eca4 100644 --- a/src/ifcopenshell-python/ifcopenshell/template.py +++ b/src/ifcopenshell-python/ifcopenshell/template.py @@ -23,6 +23,8 @@ import uuid from .file import file from .guid import compress from .ifcopenshell_wrapper import version +from typing import Optional + # A quick way to setup an 'empty' IFC file, taken from: # http://academy.ifcopenshell.org/creating-a-simple-wall-with-property-set-and-quantity-information/ @@ -68,17 +70,17 @@ DEFAULTS = { def create( - filename=None, - timestring=None, - organization=None, - creator=None, - schema_identifier=None, - application_version=None, - timestamp=None, - application=None, - project_globalid=None, - project_name=None, -): + filename: Optional[str] = None, + timestring: Optional[str] = None, + organization: Optional[str] = None, + creator: Optional[str] = None, + schema_identifier: Optional[str] = None, + application_version: Optional[str] = None, + timestamp: Optional[str] = None, + application: Optional[str] = None, + project_globalid: Optional[str] = None, + project_name: Optional[str] = None, +) -> file: d = dict(locals()) def _(): diff --git a/src/ifcsverchok/__init__.py b/src/ifcsverchok/__init__.py index 19f072dc77..d3d12aef20 100644 --- a/src/ifcsverchok/__init__.py +++ b/src/ifcsverchok/__init__.py @@ -185,8 +185,8 @@ class IFC_Sv_write_file(bpy.types.Operator): def poll(cls, context): return any("IFC" in n for n in context.space_data.edit_tree.nodes.keys()) - def ensure_hirarchy(self, file): - elements_in_buildings = set() + def ensure_hirarchy(self, file: ifcopenshell.file) -> None: + elements_in_buildings: set[ifcopenshell.entity_instance] = set() if len(file.by_type("IfcBuilding")) == 0: my_building = ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcBuilding", name="My Building") elements = ifcopenshell.util.element.get_decomposition(my_building) @@ -269,6 +269,7 @@ class IFC_PT_write_file_panel(bpy.types.Panel): def poll(cls, context): if context.space_data.edit_tree and any("IFC" in n for n in context.space_data.edit_tree.nodes.keys()): return True + return False def draw(self, context): ng = context.space_data.node_tree diff --git a/src/ifcsverchok/ifcstore.py b/src/ifcsverchok/ifcstore.py index 8e6a5b98ff..e8c167bb52 100644 --- a/src/ifcsverchok/ifcstore.py +++ b/src/ifcsverchok/ifcstore.py @@ -21,11 +21,12 @@ import ifcopenshell import ifcopenshell.api import ifcopenshell.util.representation from ifcopenshell import template +from typing import Union class SvIfcStore: path = "" - file = None + file: Union[ifcopenshell.file, None] = None schema = None cache = None cache_path = None @@ -47,7 +48,7 @@ class SvIfcStore: schema_identifiers = ["IFC4", "IFC2X3"] @staticmethod - def purge(): + def purge() -> None: SvIfcStore.path = "" SvIfcStore.file = None SvIfcStore.schema = None @@ -67,8 +68,7 @@ class SvIfcStore: SvIfcStore.schema_identifiers = ["IFC4", "IFC2X3"] @staticmethod - def create_boilerplate(): - + def create_boilerplate() -> ifcopenshell.file: file = template.create( filename="IfcSverchokDemoFile", organization=None, @@ -93,7 +93,7 @@ class SvIfcStore: return SvIfcStore.file @staticmethod - def get_file(): + def get_file() -> ifcopenshell.file: if SvIfcStore.file is None: SvIfcStore.create_boilerplate() return SvIfcStore.file