<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 2, 2013 at 1:39 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Thu, May 2, 2013 at 1:18 PM, <a href="mailto:fwierzbicki@gmail.com">fwierzbicki@gmail.com</a><br>
<<a href="mailto:fwierzbicki@gmail.com">fwierzbicki@gmail.com</a>> wrote:<br>
> On Thu, May 2, 2013 at 12:07 PM, Ethan Furman <<a href="mailto:ethan@stoneleaf.us">ethan@stoneleaf.us</a>> wrote:<br>
>> In order for the Enum convenience function to be pickleable, we have this<br>
>> line of code in the metaclass:<br>
>><br>
>>     enum_class.__module__ = sys._getframe(1).f_globals['__name__']<br>
>><br>
>> This works fine for Cpython, but what about the others?<br>
> This should work for Jython, but I can't say I like it. I believe<br>
> IronPython has a sort of speedup mode that disallows the use of<br>
> _getframe, and I'd like to add this to Jython someday.<br>
<br>
</div>This particular function is typically only called at module load time,<br>
so speeding it up isn't worth it.<br>
<br>
FWIW, as Eli pointed out, namedtuple() does the same thing (since<br>
Python 2.6), so we'll just copy that code (refactoring it doesn't have<br>
to hold up the PEP). The only other alternative I find acceptable is<br>
not to have the convenience API at all. That's Eli's call.<br></blockquote><div><br></div><div>I really prefer having the convenience API and acknowledging that it has some limitations (i.e. picking enums that were created with the convenience API and are nested in classes).<br>

</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
[Eli]<br>
<div class="im">> Would nesting the non-convenience Enum in a function or a class allow one to<br>
> pickle it? I think programmers who want their libraries to be pickle-able<br>
> already have to be aware of some restrictions about what can and cannot be<br>
> pickled.<br>
<br>
</div>Apparently it hasn't been a problem for namedtuple. Calling<br>
namedtuple() or Enum() in another function is similar to a class<br>
statement inside a function -- the resulting class isn't picklable.<br>
<br>
(But from this, don't conclude that it's not important for<br>
namedtuple() or Enum() to return a picklable class. It is important.<br>
It is just not important to try to make it work when they are called<br>
through some other wrapper -- there's just not much use for such a<br>
pattern.)<br>
<span class="HOEnZb"></span></blockquote></div><br></div><div class="gmail_extra">I agree.<br><br>Eli<br><br></div><div class="gmail_extra"><br></div></div>