[Python-Dev] PyPy, Jython, & IronPython: Enum convenience function and pickleablity (original) (raw)
Eli Bendersky eliben at gmail.com
Thu May 2 22:50:21 CEST 2013
- Previous message: [Python-Dev] PyPy, Jython, & IronPython: Enum convenience function and pickleablity
- Next message: [Python-Dev] PyPy, Jython, & IronPython: Enum convenience function and pickleablity
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, May 2, 2013 at 1:39 PM, Guido van Rossum <guido at python.org> wrote:
On Thu, May 2, 2013 at 1:18 PM, fwierzbicki at gmail.com <fwierzbicki at gmail.com> wrote: > On Thu, May 2, 2013 at 12:07 PM, Ethan Furman <ethan at stoneleaf.us> wrote: >> In order for the Enum convenience function to be pickleable, we have this >> line of code in the metaclass: >> >> enumclass.module = sys.getframe(1).fglobals['name'] >> >> This works fine for Cpython, but what about the others? > This should work for Jython, but I can't say I like it. I believe > IronPython has a sort of speedup mode that disallows the use of > getframe, and I'd like to add this to Jython someday.
This particular function is typically only called at module load time, so speeding it up isn't worth it. FWIW, as Eli pointed out, namedtuple() does the same thing (since Python 2.6), so we'll just copy that code (refactoring it doesn't have to hold up the PEP). The only other alternative I find acceptable is not to have the convenience API at all. That's Eli's call.
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).
[Eli] > Would nesting the non-convenience Enum in a function or a class allow one to > pickle it? I think programmers who want their libraries to be pickle-able > already have to be aware of some restrictions about what can and cannot be > pickled. Apparently it hasn't been a problem for namedtuple. Calling namedtuple() or Enum() in another function is similar to a class statement inside a function -- the resulting class isn't picklable. (But from this, don't conclude that it's not important for namedtuple() or Enum() to return a picklable class. It is important. It is just not important to try to make it work when they are called through some other wrapper -- there's just not much use for such a pattern.)
I agree.
Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130502/fdb5ed75/attachment.html>
- Previous message: [Python-Dev] PyPy, Jython, & IronPython: Enum convenience function and pickleablity
- Next message: [Python-Dev] PyPy, Jython, & IronPython: Enum convenience function and pickleablity
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]