This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Pickle socket enums by names
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder: IntEnum is unpicklable by previous Python versions
View: 23673
Assigned To: ethan.furman Nosy List: barry, eli.bendersky, ethan.furman, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2014-02-18 21:13 by serhiy.storchaka, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
socket_enums_pickle_by_name.patch serhiy.storchaka, 2014-02-18 21:13 review
socket_enums_pickle_by_name_2.patch serhiy.storchaka, 2015-02-08 23:13 review
Messages (9)
msg211559 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-18 21:13
As far as socked enums are platform depending, pickling them by value makes not much sense. Here is a patch which makes AddressFamily and SocketType members be pickled by name.
msg235548 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-02-08 05:08
To make sure I understand correctly:

On platform ABC the value 1 could mean SOCK_STREAM but on platform XYZ SOCK_STREAM is value 32?

Assuming the need to pickle socket types is not new, then people have been doing it, possibly with painful workarounds, on the integer values until now, and suddenly changing the pickle of a socket type from an integer into a string is going to break code.

Or am I missing something?
msg235549 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-08 07:34
I don't see how it can break code. If people use workaround that were not broken by changing SOCK_STREAM from int to enum, it shouldn't break by changing pickle representation of SOCK_STREAM.
msg235561 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-02-08 17:43
An IntEnum is just a fancy int.  You can add them, subtract them, multiply them, all that kind of thing.

If you attempt to unpickle a 3.4 _PickleByNameIntEnum on a 3.3 system, what's going to happen?
msg235562 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-08 17:53
> If you attempt to unpickle a 3.4 _PickleByNameIntEnum on a 3.3 system,
> what's going to happen?

The same as if you attempt to unpickle a 3.4 IntEnum on a 3.3 system -- 
AttributeError.
msg235576 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-08 23:13
For the socket module constants there is even better way, which supports forward compatibility, i.e. SOCK_STREAM pickled in 3.5 could be unpickled on 3.3 (replacing ints with enums breaks forward compatibility). Here is a patch.
msg238146 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-03-15 14:22
Serhiy, sorry for taking so long to get back to this -- we spent so much time making sure pickling worked I had no idea that unpickling didn't work in prior versions.
msg238485 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-03-19 00:35
Enum members that are replacing constants now pickle by name (see issue23673).
msg238490 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-03-19 06:09
Thanks Ethan.
History
Date User Action Args
2022-04-11 14:57:58adminsetgithub: 64879
2015-03-19 06:09:47serhiy.storchakasetmessages: + msg238490
2015-03-19 00:35:04ethan.furmansetstatus: open -> closed
superseder: IntEnum is unpicklable by previous Python versions
messages: + msg238485

resolution: duplicate
stage: patch review -> resolved
2015-03-15 14:22:59ethan.furmansetmessages: + msg238146
2015-02-08 23:13:21serhiy.storchakasetfiles: + socket_enums_pickle_by_name_2.patch

messages: + msg235576
2015-02-08 17:53:23serhiy.storchakasetmessages: + msg235562
2015-02-08 17:43:39ethan.furmansetmessages: + msg235561
2015-02-08 07:34:17serhiy.storchakasetmessages: + msg235549
2015-02-08 05:08:12ethan.furmansetmessages: + msg235548
2015-01-15 05:07:28ethan.furmansetassignee: ethan.furman
2014-02-18 21:13:59serhiy.storchakacreate