[issue22790] some class attributes missing from dir(Class)

Amaury Forgeot d'Arc report at bugs.python.org
Tue Nov 4 18:43:40 CET 2014


Amaury Forgeot d'Arc added the comment:

So, dir(C) contains '__mro__', but not 'mro'?

I'm -1 on the change.
>From https://docs.python.org/3.4/library/functions.html#dir :
"""
Note Because dir() is supplied primarily as a convenience for use at an interactive prompt, it tries to supply an interesting set of names more than it tries to supply a rigorously or consistently defined set of names, and its detailed behavior may change across releases. For example, metaclass attributes are not in the result list when the argument is a class.
"""

dir(sys) does not list its __str__ method, even if sys.__str__() works, because returning only the explicit content of the module is more interesting to the user.

Likewise, the implementation of dir(__class__) returns the methods and attributes of *instances* because [someone decided that] it's the most relevant info for the user.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22790>
_______________________________________


More information about the Python-bugs-list mailing list