[Python-checkins] r61917 - in python/branches/trunk-bytearray: Lib/test/string_tests.py Lib/test/test_bytes.py Objects/bytesobject.c

christian.heimes python-checkins at python.org
Wed Mar 26 00:57:06 CET 2008


Author: christian.heimes
Date: Wed Mar 26 00:57:06 2008
New Revision: 61917

Modified:
   python/branches/trunk-bytearray/Lib/test/string_tests.py
   python/branches/trunk-bytearray/Lib/test/test_bytes.py
   python/branches/trunk-bytearray/Objects/bytesobject.c
Log:
The type system of Python 2.6 has subtle differences to 3.0's. I've removed the Py_TPFLAGS_BASETYPE flags from bytearray for now. bytearray can't be subclasses until the issues with bytearray subclasses are fixed.

Modified: python/branches/trunk-bytearray/Lib/test/string_tests.py
==============================================================================
--- python/branches/trunk-bytearray/Lib/test/string_tests.py	(original)
+++ python/branches/trunk-bytearray/Lib/test/string_tests.py	Wed Mar 26 00:57:06 2008
@@ -27,6 +27,9 @@
     # Change in subclasses to change the behaviour of fixtesttype()
     type2test = None
 
+    # is the type subclass-able?
+    subclassable = True
+
     # All tests pass their arguments to the testing methods
     # as str objects. fixtesttype() can be used to propagate
     # these arguments to the appropriate type
@@ -57,7 +60,7 @@
         )
         # if the original is returned make sure that
         # this doesn't happen with subclasses
-        if object == realresult:
+        if self.subclassable and object == realresult:
             class subtype(self.__class__.type2test):
                 pass
             object = subtype(object)

Modified: python/branches/trunk-bytearray/Lib/test/test_bytes.py
==============================================================================
--- python/branches/trunk-bytearray/Lib/test/test_bytes.py	(original)
+++ python/branches/trunk-bytearray/Lib/test/test_bytes.py	Wed Mar 26 00:57:06 2008
@@ -865,6 +865,7 @@
 
 
 class FixedStringTest(test.string_tests.BaseTest):
+    subclassable = False
 
     def fixtype(self, obj):
         if isinstance(obj, str):
@@ -891,8 +892,8 @@
     type2test = bytearray
 
 
-class ByteArraySubclass(bytearray):
-    pass
+#class ByteArraySubclass(bytearray):
+#    pass
 
 class ByteArraySubclassTest(unittest.TestCase):
 
@@ -968,6 +969,15 @@
         x = subclass(newarg=4, source=b"abcd")
         self.assertEqual(x, b"abcd")
 
+class ByteArrayNotSubclassTest(unittest.TestCase):
+    def test_not_subclassable(self):
+        try:
+            class ByteArraySubclass(bytearray):
+                pass
+        except TypeError:
+            pass
+        else:
+            self.fail("Bytearray is subclassable")
 
 def test_main():
     #test.test_support.run_unittest(BytesTest)
@@ -976,7 +986,8 @@
     test.test_support.run_unittest(
         ByteArrayTest,
         ByteArrayAsStringTest,
-        ByteArraySubclassTest,
+        #ByteArraySubclassTest,
+        ByteArrayNotSubclassTest,
         BytearrayPEP3137Test)
 
 if __name__ == "__main__":

Modified: python/branches/trunk-bytearray/Objects/bytesobject.c
==============================================================================
--- python/branches/trunk-bytearray/Objects/bytesobject.c	(original)
+++ python/branches/trunk-bytearray/Objects/bytesobject.c	Wed Mar 26 00:57:06 2008
@@ -3232,7 +3232,8 @@
     PyObject_GenericGetAttr,            /* tp_getattro */
     0,                                  /* tp_setattro */
     &bytes_as_buffer,                   /* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | 
+    /* Py_TPFLAGS_BASETYPE */
+    Py_TPFLAGS_DEFAULT |  
     Py_TPFLAGS_HAVE_NEWBUFFER,          /* tp_flags */
     bytes_doc,                          /* tp_doc */
     0,                                  /* tp_traverse */


More information about the Python-checkins mailing list