[Python-checkins] CVS: python/dist/src/Misc NEWS,1.223,1.224

Tim Peters tim_one@users.sourceforge.net
Sun, 02 Sep 2001 22:47:40 -0700

Update of /cvsroot/python/python/dist/src/Misc
In directory usw-pr-cvs1:/tmp/cvs-serv12547/python/Misc

Modified Files:
Log Message:
Make dir() wordier (see the new docstring).  The new behavior is a mixed
bag.  It's clearly wrong for classic classes, at heart because a classic
class doesn't have a __class__ attribute, and I'm unclear on whether
that's feature or bug.  I'll repair this once I find out (in the
meantime, dir() applied to classic classes won't find the base classes,
while dir() applied to a classic-class instance *will* find the base
classes but not *their* base classes).

Please give the new dir() a try and see whether you love it or hate it.
The new dir([]) behavior is something I could come to love.  Here's
something to hate:

>>> class C:
...     pass
>>> c = C()
>>> dir(c)
['__doc__', '__module__']

The idea that an instance has a __doc__ attribute is jarring (of course
it's really c.__class__.__doc__ == C.__doc__; likewise for __module__).

OTOH, the code already has too many special cases, and dir(x) doesn't
have a compelling or clear purpose when x isn't a module.

Index: NEWS
RCS file: /cvsroot/python/python/dist/src/Misc/NEWS,v
retrieving revision 1.223
retrieving revision 1.224
diff -C2 -d -r1.223 -r1.224
*** NEWS	2001/09/02 23:01:43	1.223
--- NEWS	2001/09/03 05:47:38	1.224
*** 4,7 ****
--- 4,24 ----
+ - The builtin dir() now returns more information, and sometimes much
+   more, generally naming all attributes of an object, and all attributes
+   reachable from the object via its class, and from its class's base
+   classes, and so on from them too.  Example:  in 2.2a2, dir([]) returned
+   an empty list.  In 2.2a3,
+   >>> dir([])
+   ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
+    '__eq__', '__ge__', '__getattr__', '__getitem__', '__getslice__',
+    '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__le__',
+    '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__repr__',
+    '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__str__',
+    'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove',
+    'reverse', 'sort']
+   dir(module) continues to return only the module's attributes, though.
  - Overflowing operations on plain ints now return a long int rather
    than raising OverflowError.  This is a partial implementation of PEP