[Python-bugs-list] [ python-Bugs-449989 ] Make dir() more b/w compatible

noreply@sourceforge.net noreply@sourceforge.net
Mon, 03 Sep 2001 19:57:56 -0700


Bugs item #449989, was opened at 2001-08-10 20:51
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=449989&group_id=5470

Category: Type/class unification
Group: Python 2.2
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Guido van Rossum (gvanrossum)
Assigned to: Tim Peters (tim_one)
Summary: Make dir() more b/w compatible

Initial Comment:
The new dir() semantics are incompatible with Python
2.1 and before, because e.g. dir([]) returns [] instead
of ['append', ...].

One possibility would be to change dir() to use the new
introspection rules to give all instance variables and
all methods that are discoverable using the new
introspection API.

Though for classes I would not want to show the
metaclass attributes, and maybe I'd make an exception
for modules -- it may be confusing to see dir(sys)
return __class__, __getattr__ and so on.


----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2001-09-03 19:57

Message:
Logged In: YES 
user_id=31435

I'm closing this because I checked in a new dir() that acts 
as suggested.  We need more feedback on it, though.  In 
particular, distutils's dist.py, and test_pyclbr.py, both 
fell over because they were expecting dir(C) to be a 
shorthand for C.__dict__.keys() when C was a classic-class 
instance (distutils) or class (test_pyclbr).  All of the 
*complaints* about dir() in 2.2a2 stemmed from new-
class/type cases; if classic classes will go away, maybe 
it's a bearable tradeoff to make dir() act differently for 
old-style classes and new-style ones (oh, yuck ...).

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-16 08:13

Message:
Logged In: YES 
user_id=6380

Tim, would you mind implementing this?

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-10 20:52

Message:
Logged In: YES 
user_id=6380

(The idea here is that giving *more* information than before
is less likely to break old code or cause misgivings than
giving *less* information.)


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=449989&group_id=5470