libb.staticandinstancemethod
- class staticandinstancemethod(f)[source]
Bases:
objectDecorator allowing a method to work as both static and instance method.
When called on the class, self is None. When called on an instance, self is the instance.
Basic Usage (dual behavior):
>>> class Foo: ... @staticandinstancemethod ... def bar(self, x, y): ... print(self is None and "static" or "instance") >>> Foo.bar(1,2) static >>> Foo().bar(1,2) instance