How to override __getattr__
with python 3 and inheritance?
When I use the following:
class MixinA:
def __getattr__(self, item):
# Process item and return value if known
if item == 'a':
return 'MixinA'
# If it is unknown, pass it along to give
# a chance to another class to handle it
return super().__getattr__(item)
class MixinB:
def __getattr__(self, item):
# Process item and return value if known
if item == 'b':
return 'MixinB'
# If it is unknown, pass it along to give
# a chance to another class to handle it
return super().__getattr__(item)
class Example(MixinA, MixinB):
# main class
pass
I get this error.
>>> e = Example()
>>> e.a
'MixinA'
>>> e.b
'MixinB'
>>> e.c
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
...
AttributeError: 'super' object has no attribute '__getattr__'
Couldn't I just get the attribute error referencing the original class and property? That is to say:
AttributeError: 'Example' object has no attribute 'c'
PS: I found this post 'super' object not calling __getattr__ but I'm not sure to understand whether there is a solution.