[Python-checkins] CVS: python/dist/src/Lib/test test_descr.py,1.58,1.59

Tim Peters tim_one@users.sourceforge.net
Sun, 16 Sep 2001 19:38:48 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv31213/python/Lib/test

Modified Files:
	test_descr.py 
Log Message:
PyObject_Dir():  Merge in __members__ and __methods__ too (if they exist,
and are lists, and then just the string elements (if any)).

There are good and bad reasons for this.  The good reason is to support
dir() "like before" on objects of extension types that haven't migrated
to the class introspection API yet.  The bad reason is that Python's own
method objects are such a type, and this is the quickest way to get their
im_self etc attrs to "show up" via dir().  It looks much messier to move
them to the new scheme, as their current getattr implementation presents
a view of their attrs that's a untion of their own attrs plus their
im_func's attrs.  In particular, methodobject.__dict__ actually returns
methodobject.im_func.__dict__, and if that's important to preserve it
doesn't seem to fit the class introspection model at all.


Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.58
retrieving revision 1.59
diff -C2 -d -r1.58 -r1.59
*** test_descr.py	2001/09/15 06:35:55	1.58
--- test_descr.py	2001/09/17 02:38:46	1.59
***************
*** 191,194 ****
--- 191,195 ----
      cstuff = ['Cdata', 'Cmethod', '__doc__', '__module__']
      verify(dir(C) == cstuff)
+     verify('im_self' in dir(C.Cmethod))
  
      c = C()  # c.__doc__ is an odd thing to see here; ditto c.__module__.
***************
*** 198,201 ****
--- 199,203 ----
      c.cmethod = lambda self: 0
      verify(dir(c) == cstuff + ['cdata', 'cmethod'])
+     verify('im_self' in dir(c.Cmethod))
  
      class A(C):
***************
*** 205,210 ****
--- 207,214 ----
      astuff = ['Adata', 'Amethod'] + cstuff
      verify(dir(A) == astuff)
+     verify('im_self' in dir(A.Amethod))
      a = A()
      verify(dir(a) == astuff)
+     verify('im_self' in dir(a.Amethod))
      a.adata = 42
      a.amethod = lambda self: 3
***************
*** 225,232 ****
--- 229,238 ----
      c = C()
      verify(interesting(dir(c)) == cstuff)
+     verify('im_self' in dir(C.Cmethod))
  
      c.cdata = 2
      c.cmethod = lambda self: 0
      verify(interesting(dir(c)) == cstuff + ['cdata', 'cmethod'])
+     verify('im_self' in dir(c.Cmethod))
  
      class A(C):
***************
*** 236,239 ****
--- 242,246 ----
      astuff = ['Adata', 'Amethod'] + cstuff
      verify(interesting(dir(A)) == astuff)
+     verify('im_self' in dir(A.Amethod))
      a = A()
      verify(interesting(dir(a)) == astuff)
***************
*** 241,244 ****
--- 248,252 ----
      a.amethod = lambda self: 3
      verify(interesting(dir(a)) == astuff + ['adata', 'amethod'])
+     verify('im_self' in dir(a.Amethod))
  
      # Try a module subclass.