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 Vladislavs Burakovs
Recipients Vladislavs Burakovs, docs@python
Date 2018-01-06.08:54:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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.

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)

Date User Action Args
2018-01-06 08:54:03Vladislavs Burakovssetrecipients: + Vladislavs Burakovs, docs@python
2018-01-06 08:54:03Vladislavs Burakovssetmessageid: <>
2018-01-06 08:54:03Vladislavs Burakovslinkissue32501 messages
2018-01-06 08:54:02Vladislavs Burakovscreate