This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author soren
Recipients Arfrever, Trundle, barry, benjamin.peterson, eric.araujo, jcea, michael.foord, ncoghlan, r.david.murray, rhettinger, soren
Date 2011-06-04.22:13:07
SpamBayes Score 4.3849706e-09
Marked as misclassified No
Message-id <BANLkTikGU6ygqC28hVnQ0VwL9XrDhH+zbQ@mail.gmail.com>
In-reply-to <BANLkTinruXPqSG-K7dCggZ6o2Wv_XEV=Dg@mail.gmail.com>
Content
2011/6/4 Benjamin Peterson <report@bugs.python.org>:
> 2011/6/4 Soren Hansen <report@bugs.python.org>:
>> So my question is: If this change stays (which seems clear given that the only changes proposed here are ways of relaxing the type requirement of the __dir__ method's return value, not reverting the change altogether), and I have an old-style class with a __getattr__ defined, how do I make that class return whatever it would have usually returned for __dir__()?
>
> Yes, this is a limitation of magic methods on old style classes. The
> usual method is something like this:
>
>    def __getattr__(self, name):
>        if name == "__dir__":
>            return self.__dir__
>        # Other stuff
>
> Of course, the best fix is to use new-style classes. :)

If I do this:

===== test.py ======
class Foo:
    def __getattr__(self, name):
        if name == '__dir__':
            return self.__dir__
        return 'something else'

a = Foo()
print dir(a)
====================

After a lot of this:
  File "test.py", line 4, in __getattr__
    return self.__dir__
  File "test.py", line 4, in __getattr__
    return self.__dir__
  File "test.py", line 4, in __getattr__
    return self.__dir__

...I end up with a "RuntimeError: maximum recursion depth exceeded". I
can't say I'm surprised :)
History
Date User Action Args
2011-06-04 22:13:08sorensetrecipients: + soren, barry, rhettinger, jcea, ncoghlan, benjamin.peterson, eric.araujo, Arfrever, r.david.murray, michael.foord, Trundle
2011-06-04 22:13:07sorenlinkissue12248 messages
2011-06-04 22:13:07sorencreate