Christian Heimes added the comment:
https://docs.python.org/3/library/functions.html#dir also states that "The
resulting list is sorted alphabetically." The section has an example where
__dir__ returns an unsorted list but dir() returns a sorted list:
>>> class Shape:
...
Nils Diefenbach <23okrs20+pyt...@mykolab.com> added the comment:
Alright. Are there any other magic methods that do some post-processing on a
custom implementation of them ?
I couldn't think of one, which is why this behaviour appeared odd to me.
--
status: pending -> open
Christian Heimes added the comment:
dir() and __dir__ work as designed and documented:
https://docs.python.org/3/reference/datamodel.html?highlight=__dir__#object.__dir__
Called when dir() is called on the object. A sequence must be returned. dir()
converts the returned
New submission from Nils Diefenbach <23okrs20+pyt...@mykolab.com>:
When defining a custom __dir__ method in a class, calling dir() on
said class still sorts the output. This is, imo, unexpected behaviour,
especially if the order of output was specified in __dir__ and is somehow
relevant.