This question answers how to implement __getattr__
for static/class attributes - using a metaclass. However, I would like to implement __getattr__
and __getattribute__
for a class generated by type()
and to make things even more interesting, the class inherits a class which has a custom metaclass which must be executed properly.
The code summarizing the paragraph above:
class Inherited(metaclass=SomeFancyMetaclass):
...
generated_class = type("GeneratedClass", (Inherited,), {})
def __class_getattr__(cls, name): # __getattr__ for class, not sure how the code shall look exactly like
return getattr(cls, name)
setattr(generated_class, "__getattr__", __class_getattr__) # similarly for __getattribute__
The question: is this possible, and if so, how? Could someone provide a minimal working example?