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

Guido van Rossum gvanrossum@users.sourceforge.net
Mon, 03 Dec 2001 07:38:30 -0800


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

Modified Files:
	test_descr.py 
Log Message:
Address SF patch #480716 as well as related issues.

SF patch #480716 by Greg Chapman fixes the problem that super's
__get__ method always returns an instance of super, even when the
instance whose __get__ method is called is an instance of a subclass
of super.

Other issues fixed:

- super(C, C()).__class__ would return the __class__ attribute of C()
  rather than the __class__ attribute of the super object.  This is
  confusing.  To fix this, I decided to change the semantics of super
  so that it only applies to code attributes, not to data attributes.
  After all, overriding data attributes is not supported anyway.

- While super(C, x) carefully checked that x is an instance of C,
  super(C).__get__(x) made no such check, allowing for a loophole.
  This is now fixed.


Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.105
retrieving revision 1.106
diff -C2 -d -r1.105 -r1.106
*** test_descr.py	2001/11/24 21:07:01	1.105
--- test_descr.py	2001/12/03 15:38:28	1.106
***************
*** 1573,1577 ****
              return "D(%r)" % a + super(D, self).meth(a)
  
!     verify (D().meth(4) == "D(4)C(4)B(4)A(4)")
  
  def inherits():
--- 1573,1627 ----
              return "D(%r)" % a + super(D, self).meth(a)
  
!     vereq(D().meth(4), "D(4)C(4)B(4)A(4)")
! 
!     # Test for subclassing super
! 
!     class mysuper(super):
!         def __init__(self, *args):
!             return super(mysuper, self).__init__(*args)
! 
!     class E(D):
!         def meth(self, a):
!             return "E(%r)" % a + mysuper(E, self).meth(a)
! 
!     vereq(E().meth(5), "E(5)D(5)C(5)B(5)A(5)")
! 
!     class F(E):
!         def meth(self, a):
!             s = self.__super
!             return "F(%r)[%s]" % (a, s.__class__.__name__) + s.meth(a)
!     F._F__super = mysuper(F)
! 
!     vereq(F().meth(6), "F(6)[mysuper]E(6)D(6)C(6)B(6)A(6)")
! 
!     # Make sure certain errors are raised
! 
!     try:
!         super(D, 42)
!     except TypeError:
!         pass
!     else:
!         raise TestFailed, "shouldn't allow super(D, 42)"
! 
!     try:
!         super(D, C())
!     except TypeError:
!         pass
!     else:
!         raise TestFailed, "shouldn't allow super(D, C())"
! 
!     try:
!         super(D).__get__(12)
!     except TypeError:
!         pass
!     else:
!         raise TestFailed, "shouldn't allow super(D).__get__(12)"
! 
!     try:
!         super(D).__get__(C())
!     except TypeError:
!         pass
!     else:
!         raise TestFailed, "shouldn't allow super(D).__get__(C())"
  
  def inherits():