Skip to content

Commit 440714c

Browse files
author
raymond.hettinger
committed
Issue 1820: structseq objects did not work with the % formatting operator or isinstance(t, tuple).
Orignal patch (without tests) by Leif Walsh. git-svn-id: http://svn.python.org/projects/python/trunk@59967 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent fb08f25 commit 440714c

4 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lib/test/test_structseq.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ def test_tuple(self):
2626
for i in xrange(-len(t), len(t)-1):
2727
self.assertEqual(t[i], astuple[i])
2828

29+
def test_tuple_subclass(self):
30+
# Issue 1820
31+
t = time.localtime()
32+
s = ('%s ' * len(t)) % t # This used to fail because t was not a tuple subclass
33+
self.assert_(isinstance(t, tuple))
34+
2935
def test_repr(self):
3036
t = time.gmtime()
3137
self.assert_(repr(t))

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ Wojtek Walczak
686686
Charles Waldman
687687
Richard Walker
688688
Larry Wall
689+
Leif Walsh
689690
Greg Ward
690691
Barry Warsaw
691692
Steve Waterbury

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,10 @@ Library
975975
Extension Modules
976976
-----------------
977977

978+
- Issue 1820: structseq objects did not subclass from tuple so they did
979+
not pass isinstance(t, tuple) tests and they could not be passed to
980+
the % string formatting operator as an input tuple.
981+
978982
- _winreg's HKEY object has gained __enter__ and __exit__ methods to support
979983
the context manager protocol. The _winreg module also gained a new function
980984
``ExpandEnvironmentStrings`` to expand REG_EXPAND_SZ keys.

Objects/structseq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ static PyTypeObject _struct_sequence_template = {
460460
structseq_methods, /* tp_methods */
461461
NULL, /* tp_members */
462462
0, /* tp_getset */
463-
0, /* tp_base */
463+
&PyTuple_Type, /* tp_base */
464464
0, /* tp_dict */
465465
0, /* tp_descr_get */
466466
0, /* tp_descr_set */

0 commit comments

Comments
 (0)