From f9aba58342f01c6c289f87785416254d27de4aa3 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 3 Jul 2024 14:45:37 +0500 Subject: [PATCH] IfcOperator typing Added typing to make sure IfcOperator is properly implemented and not used if there are no IFC changes. --- src/blenderbim/blenderbim/tool/ifc.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/blenderbim/blenderbim/tool/ifc.py b/src/blenderbim/blenderbim/tool/ifc.py index 7aef50f864..43b8e9bd46 100644 --- a/src/blenderbim/blenderbim/tool/ifc.py +++ b/src/blenderbim/blenderbim/tool/ifc.py @@ -26,7 +26,7 @@ import blenderbim.core.tool import blenderbim.bim.handler import blenderbim.tool as tool from blenderbim.bim.ifc import IfcStore, IFC_CONNECTED_TYPE -from typing import Optional, Union, Any +from typing import Optional, Union, Any, final class Ifc(blenderbim.core.tool.Ifc): @@ -209,7 +209,22 @@ class Ifc(blenderbim.core.tool.Ifc): return occurrences class Operator: + """IFC Operator class. + + Operators that edit any IFC data should inherit from this class + and implement `_execute` method. + + `execute` method is already reserved by this class to keep track of the + IFC changes for Undo system. + """ + + @final def execute(self, context): IfcStore.execute_ifc_operator(self, context) blenderbim.bim.handler.refresh_ui_data() return {"FINISHED"} + + # NOTE: this class can't inherit from abc.ABC to use abc.abstractmethod + # because it conflicts with bpy.types.Operator. + def _execute(self, context: bpy.types.Context) -> None: + raise NotImplementedError("IFC operator must implement _execute method.")