[Python-checkins] r61934 - 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 13:25:10 CET 2008


Author: christian.heimes
Date: Wed Mar 26 13:25:09 2008
New Revision: 61934

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:
Re-enabled bytearray subclassing - all tests are passing.

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 13:25:09 2008
@@ -27,9 +27,6 @@
     # 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
@@ -60,7 +57,7 @@
         )
         # if the original is returned make sure that
         # this doesn't happen with subclasses
-        if self.subclassable and object == realresult:
+        if 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 13:25:09 2008
@@ -865,7 +865,6 @@
 
 
 class FixedStringTest(test.string_tests.BaseTest):
-    subclassable = False
 
     def fixtype(self, obj):
         if isinstance(obj, str):
@@ -892,8 +891,8 @@
     type2test = bytearray
 
 
-#class ByteArraySubclass(bytearray):
-#    pass
+class ByteArraySubclass(bytearray):
+    pass
 
 class ByteArraySubclassTest(unittest.TestCase):
 
@@ -969,16 +968,6 @@
         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)
     #test.test_support.run_unittest(AssortedBytesTest)
@@ -986,8 +975,7 @@
     test.test_support.run_unittest(
         ByteArrayTest,
         ByteArrayAsStringTest,
-        #ByteArraySubclassTest,
-        ByteArrayNotSubclassTest,
+        ByteArraySubclassTest,
         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 13:25:09 2008
@@ -3232,8 +3232,7 @@
     PyObject_GenericGetAttr,            /* tp_getattro */
     0,                                  /* tp_setattro */
     &bytes_as_buffer,                   /* tp_as_buffer */
-    /* Py_TPFLAGS_BASETYPE */
-    Py_TPFLAGS_DEFAULT |  
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
     Py_TPFLAGS_HAVE_NEWBUFFER,          /* tp_flags */
     bytes_doc,                          /* tp_doc */
     0,                                  /* tp_traverse */


More information about the Python-checkins mailing list