[issue42360] In the namedtuple documentation, mention that typename should match the variable name for the class to be pickle-able
New submission from Alejandro Gonzalez
Foo = namedtuple("Bar", "x,y") pickle.dumps(Foo(1, 2)) Traceback (most recent call last): File "<stdin>", line 1, in <module> _pickle.PicklingError: Can't pickle
: attribute lookup Bar on __main__ failed
While it is indeed odd to do such naming in the first place, it should be admissible in other circumstances not involving pickling, and it is not obvious that pickling won't work if you do so.
The pickle documentation does mention this, though:
[...]Similarly, classes are pickled by named reference, so the same restrictions in the unpickling environment apply.[...]
but for someone who encounters this error it might be difficult to figure it out from that passage.
The added documentation in namedtuple could include a pointer to that section of pickle's documentation.
----------
assignee: docs@python
components: Documentation
messages: 381007
nosy: alegonz, docs@python
priority: normal
severity: normal
status: open
title: In the namedtuple documentation, mention that typename should match the variable name for the class to be pickle-able
type: enhancement
_______________________________________
Python tracker
participants (3)
-
Alejandro Gonzalez
-
miss-islington
-
Raymond Hettinger