Message254883
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 |
|
Date |
User |
Action |
Args |
2015-11-19 08:06:26 | ashwch | set | recipients:
+ ashwch |
2015-11-19 08:06:26 | ashwch | set | messageid: <1447920386.58.0.359968299873.issue25665@psf.upfronthosting.co.za> |
2015-11-19 08:06:26 | ashwch | link | issue25665 messages |
2015-11-19 08:06:25 | ashwch | create | |
|