mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #25665: Make NamedTuple picklable.
This commit is contained in:
parent
05e3090e3a
commit
557d1eb0f3
2 changed files with 13 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue