Issue #25665: Make NamedTuple picklable.

This commit is contained in:
Guido van Rossum 2015-11-19 08:16:31 -08:00
parent 05e3090e3a
commit 557d1eb0f3
2 changed files with 13 additions and 0 deletions

View file

@ -1479,6 +1479,11 @@ 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)
# Set the module to the caller's module (otherwise it'd be 'typing').
try:
cls.__module__ = sys._getframe(1).f_globals.get('__name__', '__main__')
except (AttributeError, ValueError):
pass
return cls