Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b98dcc1

Browse files
committed
Issue #15535: Fix pickling of named tuples.
1 parent 8e596a7 commit b98dcc1

4 files changed

Lines changed: 9 additions & 0 deletions

File tree

Lib/collections/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ def __getnewargs__(self):
281281
'Return self as a plain tuple. Used by copy and pickle.'
282282
return tuple(self)
283283
284+
def __getstate__(self):
285+
'Exclude the OrderedDict from pickling'
286+
return None
287+
284288
{field_defs}
285289
'''
286290

Lib/test/test_collections.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ def test_pickle(self):
273273
q = loads(dumps(p, protocol))
274274
self.assertEqual(p, q)
275275
self.assertEqual(p._fields, q._fields)
276+
self.assertNotIn(b'OrderedDict', dumps(p, protocol))
276277

277278
def test_copy(self):
278279
p = TestNT(x=10, y=20, z=30)

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,7 @@ Trent Mick
811811
Jason Michalski
812812
Franck Michea
813813
Tom Middleton
814+
Thomas Miedema
814815
Stan Mihai
815816
Stefan Mihaila
816817
Aristotelis Mikropoulos

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ Library
4747
- Issue #17802: Fix an UnboundLocalError in html.parser. Initial tests by
4848
Thomas Barlow.
4949

50+
- Issue #15535: Fix namedtuple pickles which were picking up the OrderedDict
51+
instead of just the underlying tuple.
52+
5053
- Issue #17192: Restore the patch for Issue #11729 which was ommitted in
5154
3.3.1 when updating the bundled version of libffi used by ctypes. Update
5255
many libffi files that were missed in 3.3.1's update to libffi-3.0.13.

0 commit comments

Comments
 (0)