From 7ab03109b9e7c10edf4acfc612b888b8a54a9a83 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 19 Jun 2025 12:43:30 +0500 Subject: [PATCH] typing --- src/bonsai/bonsai/bim/prop.py | 2 +- src/bonsai/bonsai/tool/georeference.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/bonsai/bonsai/bim/prop.py b/src/bonsai/bonsai/bim/prop.py index fd42e56cee..8a72d8505f 100644 --- a/src/bonsai/bonsai/bim/prop.py +++ b/src/bonsai/bonsai/bim/prop.py @@ -86,7 +86,7 @@ cache_string.data: dict[str, str] = {} def get_attribute_enum_values(prop: "Attribute", context: bpy.types.Context) -> list[tuple[str, str, str]]: # Support weird buildingSMART dictionary mappings which behave like enums - items = [] + items: list[tuple[str, str, str]] = [] data = json.loads(prop.enum_items) if isinstance(data, dict): diff --git a/src/bonsai/bonsai/tool/georeference.py b/src/bonsai/bonsai/tool/georeference.py index 2b23345fcd..467d23dfc1 100644 --- a/src/bonsai/bonsai/tool/georeference.py +++ b/src/bonsai/bonsai/tool/georeference.py @@ -31,6 +31,7 @@ import bonsai.bim.helper from typing import Any, Union, Literal, TYPE_CHECKING if TYPE_CHECKING: + from bonsai.bim.prop import Attribute from bonsai.bim.module.georeference.prop import BIMGeoreferenceProperties @@ -53,7 +54,7 @@ class Georeference(bonsai.core.tool.Georeference): def import_projected_crs(cls) -> None: props = tool.Georeference.get_georeference_props() - def callback(name, prop, data): + def callback(name: str, prop: Union[Attribute, None], data: dict[str, Any]) -> Union[bool, None]: if name == "MapUnit": new = props.projected_crs.add() new.name = name @@ -181,10 +182,11 @@ class Georeference(bonsai.core.tool.Georeference): @classmethod def export_projected_crs(cls) -> dict[str, Any]: - def callback(attributes, prop): + def callback(attributes: dict[str, Any], prop: Attribute) -> bool: if not prop.is_null and prop.name == "MapUnit": attributes[prop.name] = tool.Ifc.get().by_id(int(prop.enum_value)) return True + return False props = cls.get_georeference_props() return bonsai.bim.helper.export_attributes(props.projected_crs, callback=callback) @@ -193,12 +195,13 @@ class Georeference(bonsai.core.tool.Georeference): def export_coordinate_operation(cls) -> dict[str, Any]: measure_type = None - def callback(attributes, prop): - global measure_type + def callback(attributes: dict[str, Any], prop: Attribute) -> bool: + nonlocal measure_type if prop.name == "Measure Type": measure_type = prop.get_value() return True elif prop.name in ("FirstCoordinate", "SecondCoordinate"): + assert measure_type attributes[prop.name] = tool.Ifc.get().create_entity(measure_type, float(prop.string_value)) return True elif prop.name == "XAxisAbscissa": @@ -216,6 +219,7 @@ class Georeference(bonsai.core.tool.Georeference): # We store our floats as string to prevent single precision data loss attributes[prop.name] = float(prop.string_value) return True + return False props = cls.get_georeference_props() return bonsai.bim.helper.export_attributes(props.coordinate_operation, callback=callback)