From 6318b2d822be0ded561a1afd0d485158614e2406 Mon Sep 17 00:00:00 2001 From: wakonig_k Date: Wed, 23 Apr 2025 14:48:03 +0200 Subject: [PATCH] fix(designer-plugin-generator): enhance super constructor validation for new style classes --- bec_widgets/utils/generate_designer_plugin.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bec_widgets/utils/generate_designer_plugin.py b/bec_widgets/utils/generate_designer_plugin.py index 53d6b712..482de765 100644 --- a/bec_widgets/utils/generate_designer_plugin.py +++ b/bec_widgets/utils/generate_designer_plugin.py @@ -109,6 +109,16 @@ class DesignerPluginGenerator: or bool(init_source.find("super().__init__(parent)") > 0) ) + # for the new style classes, we only have one super call. We can therefore check if the + # number of __init__ calls is 2 (the class itself and the super class) + num_inits = re.findall(r"__init__", init_source) + if len(num_inits) == 2 and not super_init_found: + super_init_found = bool( + init_source.find("super().__init__(parent=parent") > 0 + or init_source.find("super().__init__(parent,") > 0 + or init_source.find("super().__init__(parent)") > 0 + ) + if not cls_init_found and not super_init_found: raise ValueError( f"Widget class {self.widget.__name__} must call the super constructor with parent."