[Python-ideas] Should we improve `dir`?

Terry Reedy tjreedy at udel.edu
Sun Sep 15 01:12:08 CEST 2013


On 9/14/2013 4:54 PM, Raymond Hettinger wrote:

> On Sep 14, 2013, at 12:15 PM, David Halter
> <davidhalter88 at gmail.com
> <mailto:davidhalter88 at gmail.com>> wrote:
>
>> After discussions, I realized that I should probably bring this up in
>> python-ideas, I think the current implementation can be very confusing
>> for people trying to introspect classes with `dir`, which is IMHO its
>> typical use case.
>
> The current behavior of dir() is a bit irritating when I am teaching how
> Python works.
>
> That said, the irritation is minor and easily overcome.
>
> I would not want to change the behavior and risk breaking
> existing introspection code (that code is tends to be more
> fragile and implementation than most other code).

This was the basis for rejecting http://bugs.python.org/issue19002
``dir`` function does not work correctly with classes.
The proposal obviously broke pydoc and inspect modules.

> In other words, I just don't think it is worth changing something
> that has been in-place for a very long long time.  The minor
> benefit doesn't want the downsides that goes with API churn.

The other point is that people *usually* call dir(cls) in order to find 
the methods they can call in instances of cls:

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list