[New-bugs-announce] [issue3065] Fix pickling bug of collections.namedtuple

Alexandre Vassalotti report at bugs.python.org
Mon Jun 9 01:54:14 CEST 2008


New submission from Alexandre Vassalotti <alexandre at peadrop.com>:

There is currently a pickling bug in the namedtuple factory:

  >>> from collections import namedtuple
  >>> MemoRecord = namedtuple("MemoRecord", "key, msg")
  >>> m = MemoRecord(1,"hello")
  >>> import pickle
  >>> pickle.loads(pickle.dumps(m))
  Traceback (most recent call last):
    ...
  TypeError: __new__() takes exactly 3 positional arguments (2 given)

The bug is due to the fact that classes created by namedtuple don't
handle the __new__ arguments in the same fashion as tuple.__new__. The
fix is simply to define __getnewargs__.

----------
assignee: rhettinger
components: Library (Lib)
files: fix_namedtuple_pickling.patch
keywords: patch, patch
messages: 67853
nosy: alexandre.vassalotti, rhettinger
priority: normal
severity: normal
status: open
title: Fix pickling bug of collections.namedtuple
type: behavior
versions: Python 2.6, Python 3.0
Added file: http://bugs.python.org/file10558/fix_namedtuple_pickling.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3065>
_______________________________________


More information about the New-bugs-announce mailing list