[issue24416] Have date.isocalendar() return a structseq instance

Tal Einat report at bugs.python.org
Thu Sep 5 02:00:06 EDT 2019


Tal Einat <taleinat at gmail.com> added the comment:

> Would it be possible to tell pickle to serialize .isocalendar() as a tuple, and deserialize it from a tuple to a structseq?

The former is possible but that latter is not: If the object is pickled as a tuple, it will always be unpickled as a simple tuple. To customize unpickling, the serialized data must include the name of the class to use, and that class will never exist in earlier Python versions. I don't think there's a way around this.

However, I find Raymond's note very convincing, in that we should likely not let the unpickling issue get in the way of this improvement:

> FWIW, most things in Python that return a structseq previously returned a tuple (for example, time.localtime() and sys.version_info).
>
> This is not an unprecedented upgrade to improve the repr and provide access by field name in addition to positional access.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue24416>
_______________________________________


More information about the Python-bugs-list mailing list