Revert r53997 as per
http://mail.python.org/pipermail/python-dev/2007-March/071796.html .
I've kept a couple of still-valid extra tests in test_descr, but didn't
bother to sort through the new comments and refactorings added in r53997
to see if some of them could be kept. If so, they could go in a
follow-up check-in.
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index eda96a6..00a1dea 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1,6 +1,6 @@
# Test enhancements related to descriptors and new-style classes
-from test.test_support import verify, vereq, verbose, TestFailed, TESTFN, get_original_stdout, run_doctest
+from test.test_support import verify, vereq, verbose, TestFailed, TESTFN, get_original_stdout
from copy import deepcopy
import warnings
@@ -1466,89 +1466,65 @@
verify(someclass != object)
def errors():
- """Test that type can't be placed after an instance of type in bases.
+ if verbose: print "Testing errors..."
- >>> class C(list, dict):
- ... pass
- Traceback (most recent call last):
- TypeError: Error when calling the metaclass bases
- multiple bases have instance lay-out conflict
+ try:
+ class C(list, dict):
+ pass
+ except TypeError:
+ pass
+ else:
+ verify(0, "inheritance from both list and dict should be illegal")
- >>> class C(object, None):
- ... pass
- Traceback (most recent call last):
- TypeError: Error when calling the metaclass bases
- bases must be types
+ try:
+ class C(object, None):
+ pass
+ except TypeError:
+ pass
+ else:
+ verify(0, "inheritance from non-type should be illegal")
+ class Classic:
+ pass
- >>> class C(type(len)):
- ... pass
- Traceback (most recent call last):
- TypeError: Error when calling the metaclass bases
- type 'builtin_function_or_method' is not an acceptable base type
+ try:
+ class C(type(len)):
+ pass
+ except TypeError:
+ pass
+ else:
+ verify(0, "inheritance from CFunction should be illegal")
- >>> class Classic:
- ... def __init__(*args): pass
- >>> class C(object):
- ... __metaclass__ = Classic
+ try:
+ class C(object):
+ __slots__ = 1
+ except TypeError:
+ pass
+ else:
+ verify(0, "__slots__ = 1 should be illegal")
- >>> class C(object):
- ... __slots__ = 1
- Traceback (most recent call last):
- TypeError: Error when calling the metaclass bases
- 'int' object is not iterable
+ try:
+ class C(object):
+ __slots__ = [1]
+ except TypeError:
+ pass
+ else:
+ verify(0, "__slots__ = [1] should be illegal")
- >>> class C(object):
- ... __slots__ = [1]
- Traceback (most recent call last):
- TypeError: Error when calling the metaclass bases
- __slots__ items must be strings, not 'int'
-
- >>> class A(object):
- ... pass
-
- >>> class B(A, type):
- ... pass
- Traceback (most recent call last):
- TypeError: Error when calling the metaclass bases
- metaclass conflict: type must occur in bases before other non-classic base classes
-
- Create two different metaclasses in order to setup an error where
- there is no inheritance relationship between the metaclass of a class
- and the metaclass of its bases.
-
- >>> class M1(type):
- ... pass
- >>> class M2(type):
- ... pass
- >>> class A1(object):
- ... __metaclass__ = M1
- >>> class A2(object):
- ... __metaclass__ = M2
- >>> class B(A1, A2):
- ... pass
- Traceback (most recent call last):
- TypeError: Error when calling the metaclass bases
- metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
- >>> class B(A1):
- ... pass
-
- Also check that assignment to bases is safe.
-
- >>> B.__bases__ = A1, A2
- Traceback (most recent call last):
- TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
- >>> B.__bases__ = A2,
- Traceback (most recent call last):
- TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
-
- >>> class M3(M1):
- ... pass
- >>> class C(object):
- ... __metaclass__ = M3
- >>> B.__bases__ = C,
- Traceback (most recent call last):
- TypeError: assignment to __bases__ may not change metatype
- """
+ class M1(type):
+ pass
+ class M2(type):
+ pass
+ class A1(object):
+ __metaclass__ = M1
+ class A2(object):
+ __metaclass__ = M2
+ try:
+ class B(A1, A2):
+ pass
+ except TypeError:
+ pass
+ else:
+ verify(0, "finding the most derived metaclass should have failed")
def classmethods():
if verbose: print "Testing class methods..."
@@ -4331,6 +4307,7 @@
slots()
slotspecials()
dynamics()
+ errors()
classmethods()
classmethods_in_c()
staticmethods()
@@ -4399,9 +4376,6 @@
notimplemented()
test_assign_slice()
- from test import test_descr
- run_doctest(test_descr, verbosity=True)
-
if verbose: print "All OK"
if __name__ == "__main__":