pyiron_workflow.overloading module

pyiron_workflow.overloading.overloaded_classmethod(class_method)[source]

Decorator to define a method that behaves like both a classmethod and an instancemethod under the same name.

Parameters:

instance_method – A method defined on the same object as the decorated method, to be used when an instance of the object calls the decorated method ( instead of a class call)

Returns:

  • descriptor – A descriptor that dispatches to the classmethod when accessed via the class, and to the given instance method when accessed via an instance.

  • Examples – >>> class Foo: … def __init__(self, y): … self.y = y … … @classmethod … def _doit_classmethod(cls, x): … return f”Class {cls.__name__} doing {x}” … … @overloaded_classmethod(class_method=_doit_classmethod) … def doit(self, x): … return f”Instance of type {type(self).__name__} doing {x} + {self.y}” … >>> Foo.doit(10) ‘Class Foo doing 10’ >>> Foo(5).doit(20) ‘Instance of type Foo doing 20 + 5’