Showing content from http://mail.python.org/pipermail/python-dev/attachments/20140218/815f1477/attachment.html below:
<div dir="ltr">I'm confused. Hasn't this all been decided by the PEP long ago?<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 18, 2014 at 9:11 AM, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us" target="_blank">ethan@stoneleaf.us</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On 02/15/2014 11:01 AM, Serhiy Storchaka wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
How Enum items should be pickled, by value or by name?<br>
<br>
I think that Enum will be used to collect system-depending constants, so the value of AddressFamily.AF_UNIX can be 1 on<br>
one platform and 2 on other. If pickle enums by value, then pickled AddressFamily.AF_INET on on platform can be<br>
unpickled as AddressFamily.AF_UNIX on other platform. This looks weird and contrary to the nature of enums.<br>
</blockquote>
<br></div>
There is one more wrinkle to pickling by name (it's actually still there in pickle by value, just more obvious in pickle by name) -- aliases. It seems to me the most common scenario to having a name represent different values on different systems is when on system A they are different, but on system B they are the same:<br>
<br>
System A:<br>
<br>
class SystemEnum(Enum):<br>
value1 = 1<br>
value2 = 2<br>
<br>
System B:<br>
<br>
class SystemEnum(Enum):<br>
value1 = 1<br>
value2 = 1<br>
<br>
If you're on system B there is no way to pickle (by name or value) value2 such that we get value2 back on system A. The only way I know of to make that work would be to dispense with identity comparison, use the normal == comparison, and have aliases actually be separate objects (we could still use singletons, but it would be one per name instead of the current one per value, and it would also be an implementation detail).<br>
<br>
Thoughts?<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
~Ethan~</font></span><div class="HOEnZb"><div class="h5"><br>
______________________________<u></u>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" target="_blank">https://mail.python.org/<u></u>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" target="_blank">https://mail.python.org/<u></u>mailman/options/python-dev/<u></u>guido%40python.org</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)
</div>
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4