How does the super type present itself and do lookups?

Adam Preble adam.preble at gmail.com
Mon Mar 23 02:40:37 EDT 2020


On Thursday, March 19, 2020 at 5:02:46 PM UTC-5, Greg Ewing wrote:
> On 11/03/20 7:02 am, Adam Preble wrote:
> > Is this foo attribute being looked up in an override of __getattr__, __getattribute__, or is it a reserved slot that's internally doing this? That's what I'm trying to figure out.
> 
> Looking at the source in Objects/typeobject.c, it uses the
> tp_getattro type slot, which corresponds to __getattribute__.

Thanks for taking the time to look this up for me. I saw the message soon after you originally posted it, but it took me this long to sit down and poke at everything some more.

I don't doubt what you got from the source, but I am trying to figure out how I could have inferred that from the code I was trying. It looks like child_instance.__getattribute__ == child_instance.super().__getattribute__. They print out with the same address and pass an equality comparison. That implies that they are the same, and that the super type is NOT doing something special with that slot.

Given that super().__getattribute__ internally ultimately should be something else, I am guessing there is something else at play causing an indirection.

I have two reasons to be interested in this:
1. There may be obscure behavior I should worry about in general if I'm trying to default to mimicking Python and the data model for my own stuff.
2. I need to improve my kung fu when I'm inspecting these objects so I don't get hung up on stuff like this in the future.

The bright side is having a custom get attribute implementation is pretty much correct, although mine would have c.__getattribute != c.super().__getattribute__.


More information about the Python-list mailing list