Message309544
Documentation page [1] says "If the object has a method named __dir__(), this method will be called and must return the list of attributes.".
It seems that on Python 3.6 it only works if the *class* has a method named __dir__. Should the documentation be changed?
Microsoft Windows [Version 10.0.16299.192]
(c) 2017 Microsoft Corporation. All rights reserved.
D:\Users\wlad>python
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class C: pass
...
>>> x = C()
>>> import types
>>> x.__dir__ = types.MethodType(lambda _:[], x)
>>> dir(x)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
>>> C.__dir__ = types.MethodType(lambda _:[], x)
>>> dir(x)
[]
[1] https://docs.python.org/3/library/functions.html |
|
Date |
User |
Action |
Args |
2018-01-06 08:54:03 | Vladislavs Burakovs | set | recipients:
+ Vladislavs Burakovs, docs@python |
2018-01-06 08:54:03 | Vladislavs Burakovs | set | messageid: <1515228843.27.0.467229070634.issue32501@psf.upfronthosting.co.za> |
2018-01-06 08:54:03 | Vladislavs Burakovs | link | issue32501 messages |
2018-01-06 08:54:02 | Vladislavs Burakovs | create | |
|