[Python-Dev] PyPy, Jython, & IronPython: Enum convenience function and pickleablity
benjamin at python.org
Thu May 2 23:19:30 CEST 2013
2013/5/2 Eli Bendersky <eliben at gmail.com>:
> On Thu, May 2, 2013 at 1:10 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>> On Thu, 2 May 2013 15:48:14 -0400
>> Benjamin Peterson <benjamin at python.org> wrote:
>> > 2013/5/2 Ethan Furman <ethan at stoneleaf.us>:
>> > > In order for the Enum convenience function to be pickleable, we have
>> > > this
>> > > line of code in the metaclass:
>> > >
>> > > enum_class.__module__ = sys._getframe(1).f_globals['__name__']
>> > >
>> > > This works fine for Cpython, but what about the others?
>> > Regardless of that, perhaps we should come up with better ways to do
>> > this.
>> Two things that were suggested in private:
>> 1) ask users to pass the module name to the convenience function
>> explicitly (i.e. pass "seasonmodule.Season" instead of "Season" as the
>> class "name"). Guido doesn't like it :-)
>> 2) dicth the "convenience function" and replace it with a regular
>> class-based syntax. Ethan doesn't like it :-)
> Re (2), we already have the hack in stdlib in namedtuple, so not allowing it
> for an enum is a step backwards. If sys._getframe(1).f_globals['__name__']
> feels hackish, maybe it can be shortened to a convenience function the
> stdlib provides? Are there conditions where it doesn't produce what we
> expect from it? The point at which the enumeration is defined resides in
> *some* module, no?
I disagree that not allowing code smell to spread is a step backwards.
Rather we should realize that this is a common problem and find a
proper solution rather than further propogating this hack.
More information about the Python-Dev