On Wed, Jun 14, 2017 at 8:09 AM, Terry Reedy <tjre...@udel.edu> wrote:
> Perhaps you are looking for __dir__, called by dir().
>
> " dir([object])
>
>     Without arguments, return the list of names in the current local scope.
> With an argument, attempt to return a list of valid attributes for that
> object.
>
>     If the object has a method named __dir__(), this method will be called
> and must return the list of attributes."

AIUI the OP is looking to implement __dir__, but make use of *what
dir() would have returned* in that function. Something like:

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?

ChrisA
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to