Skip to content

Commit e1bcc64

Browse files
authored
[ENH] add _get_clone_plugins to allow packages to customize clone plugins (#383)
Adds a `_get_clone_plugins` method to `BaseObject` to allow packages to override the `clone` logic with custom plugins.
1 parent badd7d4 commit e1bcc64

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

skbase/base/_base.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,41 @@ def clone(self):
176176
------
177177
RuntimeError if the clone is non-conforming, due to faulty ``__init__``.
178178
"""
179-
self_clone = _clone(self, base_cls=BaseObject)
179+
# get plugins for cloning, if present (empty by default)
180+
clone_plugins = self._get_clone_plugins()
181+
182+
# clone the object
183+
self_clone = _clone(self, base_cls=BaseObject, clone_plugins=clone_plugins)
184+
185+
# check the clone, if check_clone is set (False by default)
180186
if self.get_config()["check_clone"]:
181187
_check_clone(original=self, clone=self_clone)
188+
189+
# return the clone
182190
return self_clone
183191

192+
@classmethod
193+
def _get_clone_plugins(cls):
194+
"""Get clone plugins for BaseObject.
195+
196+
Can be overridden in subclasses to add custom clone plugins.
197+
198+
If implemented, must return a list of clone plugins for descendants.
199+
200+
Plugins are loaded ahead of the default plugins, and are used in the order
201+
they are returned.
202+
This allows extenders to override the default behaviours, if desired.
203+
204+
Returns
205+
-------
206+
list of str
207+
List of clone plugins for descendants.
208+
Each plugin must inherit from ``BaseCloner``
209+
in ``skbase.base._clone_plugins``, and implement
210+
the methods ``_check`` and ``_clone``.
211+
"""
212+
return None
213+
184214
@classmethod
185215
def _get_init_signature(cls):
186216
"""Get class init signature.

0 commit comments

Comments
 (0)