[Python-Dev] PEP-435 reference implementation (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Fri May 3 03:10:04 CEST 2013
- Previous message: [Python-Dev] PEP-435 reference implementation
- Next message: [Python-Dev] PEP-435 reference implementation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, May 2, 2013 at 11:37 AM, Steven D'Aprano <steve at pearwood.info> wrote:
On 02/05/13 08:54, Nick Coghlan wrote:
If enums had an "asdict" method that returned an ordered dictionary, you could do:
class MoreColors(Enum): locals().update(Colors.asdict()) 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 | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-Dev] PEP-435 reference implementation
- Next message: [Python-Dev] PEP-435 reference implementation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]