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

Chris Angelico rosuav at gmail.com
Wed Jun 14 19:51:09 EDT 2017


On Thu, Jun 15, 2017 at 6:54 AM, Barry Scott <barry at barrys-emacs.org> wrote:
>> class Magic:
>>    def __getattr__(self, attr):
>>        if attr in self.generatables:
>>            return self.generated_value(attr)
>>        raise AttributeError
>>    def __dir__(self):
>>        return default_dir(self) + self.generatables
>>
>> For that purpose, is it possible to use super().__dir__()? Are there
>> any considerations where that would fail?
>
> Remember that I need to do this in the C API and I want default_dir of self in C not python.
>
> super().__dir__ looks at the class above me that is typically object() and so is not useful
> as it does not list the member function from my class or __mro__ or other stuff I may not be aware of
> that is important to return.

Right, thank you. That's the bit I wasn't aware of - the reason that
__dir__ can't be used. So in terms of defining the problem, this is a
solid piece of info.

ChrisA


More information about the Python-ideas mailing list