New submission from Antony Lee <anntzer....@gmail.com>:

A quick check suggests that enum entries can be programmatically created by 
assigning to locals() in the Enum body:

   class E(Enum): locals()["a"] = 1
   E.a  # -> <E.a: 'a'>

However, using locals().update(...) doesn't, and silently does the wrong thing:

   class E(Enum): locals().update({"a": "a"})
   E.a  # -> 'a'

(Yes, in this simple case, I could just use the functional API (`E = Enum("E", 
[("a", "a")])`), but the above is simpler if I also want e.g. to define methods 
for the Enum.

----------
components: Library (Lib)
messages: 325864
nosy: Antony.Lee
priority: normal
severity: normal
status: open
title: locals().update doesn't work in Enum body, even though direct assignment 
to locals() does
versions: Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34750>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to