[New-bugs-announce] [issue19002] ``dir`` function does not work correctly with classes.

David Halter report at bugs.python.org
Wed Sep 11 08:20:51 CEST 2013


New submission from David Halter:

I recently stumbled over the ``dir`` function not working correctly with classes. This means that ``dir(object)`` won't list ``object.__bases__`` or ``object.__subclasses`` (and many other useful methods).

I think that we should change that. The C function ``type_dir`` (in ``Objects/typeobject.c``) has a documentation entry which states:

"We deliberately don't suck up its __class__, as methods belonging to the metaclass would probably be more confusing than helpful."

I think that that's not true. The current behaviour of ``dir`` is way more confusing, since ``dir`` is typically the tool how we find out about magic methods.

I wrote about it in more details here: http://jedidjah.ch/code/2013/9/8/wrong_dir_function/

----------
components: Interpreter Core
messages: 197471
nosy: davidhalter
priority: normal
severity: normal
status: open
title: ``dir`` function does not work correctly with classes.
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5

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


More information about the New-bugs-announce mailing list