[Python-ideas] Restore the __members__ behavior to python3 for C extension writers

Nick Coghlan ncoghlan at gmail.com
Fri Jun 16 04:46:05 EDT 2017


On 16 June 2017 at 07:44, Barry Scott <barry at barrys-emacs.org> wrote:
> But I need the result of __dir__ for my object not its base. Then I need to
> add in the list of member attributes that are missing because python
> itself has no knowledge of them they are accessed via getattr().

The C code:

   dir_result = PyObject_CallMethod(base_type, "__dir__", "O", self);

is roughly equivalent to the Python code:

    dir_result = BaseType.__dir__(self)

That is, it's calling the base type's __dir__ method, but it's still
using the subclass *instance*.

It's the same pattern people use to call a base type's __getattr__ or
__getattribute__ for the subclass implementation of those methods,
just without multiple inheritance support (since calling super() from
C is painful).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list