This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ashwch
Recipients ashwch
Date 2015-11-19.08:06:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1447920386.58.0.359968299873.issue25665@psf.upfronthosting.co.za>
In-reply-to
Content
Currently namedtuple(https://hg.python.org/cpython/file/3.5/Lib/collections/__init__.py#l418) sets the `__module__` attribute by looking up `__name__` in calling frame's globals. As in the case of `typing.NamedTuple` it is always going to be 'typing' pickle will raise an error.

Instead of this `typing.NamedTuple` should override the `__module__` attribute itself because it has info about the actual caller frame.

Something like this should work fine:

```
def NamedTuple(typename, fields):

    fields = [(n, t) for n, t in fields]
    cls = collections.namedtuple(typename, [n for n, t in fields])
    cls._field_types = dict(fields)
    try:
        cls.__module__ = sys._getframe(1).f_globals.get('__name__', '__main__')
    except (AttributeError, ValueError):
        pass
    return cls
```

Related: http://stackoverflow.com/q/33796490/846892
History
Date User Action Args
2015-11-19 08:06:26ashwchsetrecipients: + ashwch
2015-11-19 08:06:26ashwchsetmessageid: <1447920386.58.0.359968299873.issue25665@psf.upfronthosting.co.za>
2015-11-19 08:06:26ashwchlinkissue25665 messages
2015-11-19 08:06:25ashwchcreate