Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
better check of overriden '__init__' method
Browse files Browse the repository at this point in the history
  • Loading branch information
iLLiCiTiT committed Sep 5, 2023
1 parent 176fc9a commit e2c3a0f
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion openpype/pipeline/create/creator_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}."
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit e2c3a0f

Please sign in to comment.