Trying to use decorator-classes on a base class in python 3 but not fully understanding the behavior I observe.
class tagged:
""" Decorator itself. """
def __init__(self, regClass, *args, **kwargs):
""" called after class definition """
print(self, regClass, regClass.name)
@tagged
class Base(object):
name = "Base class"
#class Derived(Base):
# name = "Derived class"
The first class works as expected, and I see
__init__ <__main__.tagged object at 0x100632cc0> <class '__main__.Base'>
Base class
But when I uncomment Derived
it is not forwarding its arguments to the decorator the way I expected.
_init__ <__main__.tagged object at 0xb74c516c> <class '__main__.Base'>
Base class
__init__ <__main__.tagged object at 0xb74c51cc> Derived
Traceback (most recent call last):
File "./prog.py", line 10, in <module>
File "./prog.py", line 4, in __init__
AttributeError: 'str' object has no attribute 'name'
My motivation here is improving my Pyfu, in particular I'm trying out various ways of achieving self-registration in sub-modules (specifically, these modules are sub-commands which register themselves with a sub-command index and then supply their argument sets to the parser if and only if the specific sub-command is selected).