inheriting from C types

Renzo Tomaselli renzo.tomaselli at tecnotp.it
Wed Jul 17 08:35:20 EDT 2002


Tim Peters <tim.one at comcast.net> wrote in message news:<mailman.1026878665.24885.python-list at python.org>...
> [Martin v. Loewis, out of context]
> > What is k.__mro__?
> 
> [Greg Ewing]
> > I believe it stands for Method Resolution Order, and
> > it contains a flattened list of all the base classes,
> > in the order they should be searched for methods.
> 
> All correct, except that it also contains the class itself first (unless you
> create a really weird custom metatype that defines a bizarre resolution
> order for its instances).  But Martin knows that.  In context, if we knew
> the *value* of k.__mro__, that would help in answering the OP's question.

I finally solved it and indeed k.__mro__ contained all base classes.
It's a matter of filling in slot tp_methods of a C type, instead of
relying upon tp_getattr(o) and alike.
Then I discovered that PyType_Ready does the magics of
creating/filling in tp_dict from tp_methods, tp_members and others.
Once a tp_dict is ready for each base class, we can find any symbol
though the mro-flattened base hierarchy of any derived class.
Thanks,

Renzo



More information about the Python-list mailing list