From e2c3a0f5be2be18ab71cfbd65632f66f1a8b218e Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Tue, 5 Sep 2023 17:33:25 +0200 Subject: [PATCH 1/2] better check of overriden '__init__' method --- openpype/pipeline/create/creator_plugins.py | 30 ++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/openpype/pipeline/create/creator_plugins.py b/openpype/pipeline/create/creator_plugins.py index de9cc7cff3f..ab0d36e67ef 100644 --- a/openpype/pipeline/create/creator_plugins.py +++ b/openpype/pipeline/create/creator_plugins.py @@ -214,7 +214,7 @@ def __init__( # Backwards compatibility for system settings self.apply_settings(project_settings, system_settings) - init_overriden = self.__class__.__init__ is not BaseCreator.__init__ + init_overriden = self._method_is_overriden("__init__") if init_overriden or expect_system_settings: self.log.warning(( "WARNING: Source - Create plugin {}." @@ -225,6 +225,19 @@ def __init__( " need to keep system settings." ).format(self.__class__.__name__)) + def _method_is_overriden(self, method_name): + """Check if method is overriden on objects class. + + Implemented for deprecation warning validation on init. + + Returns: + bool: True if method is overriden on objects class. + """ + + cls_method = getattr(BaseCreator, method_name) + obj_method = getattr(self.__class__, method_name) + return cls_method is not obj_method + def apply_settings(self, project_settings): """Method called on initialization of plugin to apply settings. @@ -578,6 +591,11 @@ def __init__(self, *args, **kwargs): ) super(Creator, self).__init__(*args, **kwargs) + def _method_is_overriden(self, method_name): + cls_method = getattr(Creator, method_name) + obj_method = getattr(self.__class__, method_name) + return cls_method is not obj_method + @property def show_order(self): """Order in which is creator shown in UI. @@ -720,6 +738,11 @@ class HiddenCreator(BaseCreator): def create(self, instance_data, source_data): pass + def _method_is_overriden(self, method_name): + cls_method = getattr(HiddenCreator, method_name) + obj_method = getattr(self.__class__, method_name) + return cls_method is not obj_method + class AutoCreator(BaseCreator): """Creator which is automatically triggered without user interaction. @@ -731,6 +754,11 @@ def remove_instances(self, instances): """Skip removement.""" pass + def _method_is_overriden(self, method_name): + cls_method = getattr(AutoCreator, method_name) + obj_method = getattr(self.__class__, method_name) + return cls_method is not obj_method + def discover_creator_plugins(*args, **kwargs): return discover(BaseCreator, *args, **kwargs) From c3847aec5186d26414f220369a89234f70740706 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Tue, 5 Sep 2023 17:55:37 +0200 Subject: [PATCH 2/2] removed '_method_is_overriden' and use explicit class checks --- openpype/pipeline/create/creator_plugins.py | 40 ++++++--------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/openpype/pipeline/create/creator_plugins.py b/openpype/pipeline/create/creator_plugins.py index ab0d36e67ef..6aa08cae705 100644 --- a/openpype/pipeline/create/creator_plugins.py +++ b/openpype/pipeline/create/creator_plugins.py @@ -214,8 +214,16 @@ def __init__( # Backwards compatibility for system settings self.apply_settings(project_settings, system_settings) - init_overriden = self._method_is_overriden("__init__") - if init_overriden or expect_system_settings: + init_use_base = any( + self.__class__.__init__ is cls.__init__ + for cls in { + BaseCreator, + Creator, + HiddenCreator, + AutoCreator, + } + ) + if not init_use_base or expect_system_settings: self.log.warning(( "WARNING: Source - Create plugin {}." " System settings argument will not be passed to" @@ -225,19 +233,6 @@ def __init__( " need to keep system settings." ).format(self.__class__.__name__)) - def _method_is_overriden(self, method_name): - """Check if method is overriden on objects class. - - Implemented for deprecation warning validation on init. - - Returns: - bool: True if method is overriden on objects class. - """ - - cls_method = getattr(BaseCreator, method_name) - obj_method = getattr(self.__class__, method_name) - return cls_method is not obj_method - def apply_settings(self, project_settings): """Method called on initialization of plugin to apply settings. @@ -591,11 +586,6 @@ def __init__(self, *args, **kwargs): ) super(Creator, self).__init__(*args, **kwargs) - def _method_is_overriden(self, method_name): - cls_method = getattr(Creator, method_name) - obj_method = getattr(self.__class__, method_name) - return cls_method is not obj_method - @property def show_order(self): """Order in which is creator shown in UI. @@ -738,11 +728,6 @@ class HiddenCreator(BaseCreator): def create(self, instance_data, source_data): pass - def _method_is_overriden(self, method_name): - cls_method = getattr(HiddenCreator, method_name) - obj_method = getattr(self.__class__, method_name) - return cls_method is not obj_method - class AutoCreator(BaseCreator): """Creator which is automatically triggered without user interaction. @@ -754,11 +739,6 @@ def remove_instances(self, instances): """Skip removement.""" pass - def _method_is_overriden(self, method_name): - cls_method = getattr(AutoCreator, method_name) - obj_method = getattr(self.__class__, method_name) - return cls_method is not obj_method - def discover_creator_plugins(*args, **kwargs): return discover(BaseCreator, *args, **kwargs)