New submission from Ashwini Chaudhary: 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 ---------- components: Library (Lib) messages: 254883 nosy: montysinngh priority: normal severity: normal status: open title: typing.NamedTuple instances are not picklable. versions: Python 3.5 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25665> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com