On Thu, May 2, 2013 at 11:37 AM, Steven D'Aprano <st...@pearwood.info> wrote: > On 02/05/13 08:54, Nick Coghlan wrote: > >> If enums had an "as_dict" method that returned an ordered dictionary, you >> could do: >> >> class MoreColors(Enum): >> locals().update(Colors.as_dict()) > > > > Surely that is an implementation-specific piece of code? Writing to locals() > is not guaranteed to work, and the documentation warns against it. > > http://docs.python.org/3/library/functions.html#locals
I've long thought we should stop being wishy-washy about modification of locals(), and make the current CPython behaviour part of the language spec: - at module scope, locals() must return the same thing as globals(), which must be the actual module namespace - at class scope, it must return the namespace returned by __prepare__() - at function scope, it returns a snapshot of the current locals and free variables, and thus does not support modifications (and may not see subsequent changes) I'll start a separate thread about that. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com