]> granicus.if.org Git - python/commitdiff
Issue 1820: structseq objects did not work with the % formatting operator or isinsta...
authorRaymond Hettinger <python@rcn.com>
Tue, 15 Jan 2008 03:02:37 +0000 (03:02 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 15 Jan 2008 03:02:37 +0000 (03:02 +0000)
Orignal patch (without tests) by Leif Walsh.

Lib/test/test_structseq.py
Misc/ACKS
Misc/NEWS
Objects/structseq.c

index 83c7ccf57d14e23df56d9033173f849f7e2d478f..02c2f72fdfb4d33af329ab66d64c46ac30ce4e11 100644 (file)
@@ -26,6 +26,12 @@ class StructSeqTest(unittest.TestCase):
         for i in xrange(-len(t), len(t)-1):
             self.assertEqual(t[i], astuple[i])
 
+    def test_tuple_subclass(self):
+        # Issue 1820
+        t = time.localtime()
+        s = ('%s ' * len(t)) % t        # This used to fail because t was not a tuple subclass
+        self.assert_(isinstance(t, tuple))
+
     def test_repr(self):
         t = time.gmtime()
         self.assert_(repr(t))
index 2ae4528b0ac0a5b266a2d1efd17a78b96ffaac11..2090f85a19f104ec2d3279e9f3fb4253ba01aa4a 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -686,6 +686,7 @@ Wojtek Walczak
 Charles Waldman
 Richard Walker
 Larry Wall
+Leif Walsh
 Greg Ward
 Barry Warsaw
 Steve Waterbury
index 32dab1059cdd6c40e0e23fc9c2151d0d2d9b98c7..048e9842b66ac5a357e9732bd04d77b98e8b9171 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -975,6 +975,10 @@ Library
 Extension Modules
 -----------------
 
+- Issue 1820: structseq objects did not subclass from tuple so they did
+  not pass isinstance(t, tuple) tests and they could not be passed to
+  the % string formatting operator as an input tuple.
+
 - _winreg's HKEY object has gained __enter__ and __exit__ methods to support
   the context manager protocol.  The _winreg module also gained a new function
   ``ExpandEnvironmentStrings`` to expand REG_EXPAND_SZ keys.
index b6126bae467e99b038542b1bd1076acc2fd9c65b..6b1b5905897eda5ca9287a3b72b0134cb05da6f1 100644 (file)
@@ -460,7 +460,7 @@ static PyTypeObject _struct_sequence_template = {
        structseq_methods,                      /* tp_methods */
         NULL,                                  /* tp_members */
        0,                                      /* tp_getset */
-       0,                                      /* tp_base */
+       &PyTuple_Type,                          /* tp_base */
        0,                                      /* tp_dict */
        0,                                      /* tp_descr_get */
        0,                                      /* tp_descr_set */