[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2020-12-10 Thread Antony Lee
Change by Antony Lee : -- nosy: -Antony.Lee ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2020-12-10 Thread Antony Lee
Antony Lee added the comment: Thanks! -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2020-12-10 Thread Ethan Furman
Change by Ethan Furman : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___

[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2020-12-10 Thread Ethan Furman
Ethan Furman added the comment: New changeset a65828717982e6a56382d7aff738478f5b5b25d0 by Ethan Furman in branch 'master': bpo-34750: [Enum] add `_EnumDict.update()` support (GH-23725) https://github.com/python/cpython/commit/a65828717982e6a56382d7aff738478f5b5b25d0 --

[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2020-12-09 Thread Ethan Furman
Ethan Furman added the comment: Okay, you convinced me. I would ask two things, though: - use vars() instead of locals() - split the one-liner ;) class Foo(Enum): vars().update({ k: v for k, v in foo_defines.items() if

[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2020-12-09 Thread Ethan Furman
Change by Ethan Furman : -- keywords: +patch pull_requests: +22586 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/23725 ___ Python tracker

[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2020-12-09 Thread Ethan Furman
Change by Ethan Furman : -- stage: -> needs patch type: -> enhancement versions: +Python 3.10 -Python 3.8 ___ Python tracker ___

[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2020-09-13 Thread Antony Lee
Antony Lee added the comment: To be honest, I don't really remember what exact use case I had in my mind 2 years ago (as I probably worked around it in one way or another). However, one example that I can think of (and that I have actually implemented before) is auto-conversion of C

[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2020-09-12 Thread Ethan Furman
Ethan Furman added the comment: Antony, My apologies for the delay. What I would like to see is a real example of how you would use this new feature if it were implemented. I'm guessing it would look something like: class MyEnum(Enum): locals.update(*some magic here*)

[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2018-09-22 Thread Antony Lee
Antony Lee added the comment: > I agree though that adding an update method would be nice though and can be > done in just a few lines of code. Again, this can be done just be inheriting the methods from MutableMapping. In fact even now one can just write class E(Enum):

[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2018-09-21 Thread Dan Snider
Dan Snider added the comment: It's working as intended. locals() and vars() simply returns the current frame's f_locals. In functions, modifying this usually accomplishes nothing useful because the code object has OPTIMIZED and NEWLOCALS flags set, meaning local variables are looked up or

[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2018-09-21 Thread Antony Lee
Antony Lee added the comment: > encourage the common assumption that locals() returns a dict where mutating > it actually works, since it usually doesn't. It does at global and class scope, not at function scope. FWIW, PEP558 (admittedly not accepted yet) proposes to modify the

[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2018-09-21 Thread Josh Rosenberg
Josh Rosenberg added the comment: The documentation for locals ( https://docs.python.org/3/library/functions.html#locals ) specifically states: Note: The contents of this dictionary should not be modified; changes may not affect the values of local and free variables used by the

[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2018-09-20 Thread Antony Lee
Antony Lee added the comment: I have a personal helper function for writing (Qt) GUIs that generates ComboBoxes from Enums; essentially something like class Choices(Enum): choice1 = "text for choice 1" choice2 = "text for choice 2" def callback(choice: Choices):

[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2018-09-20 Thread Ethan Furman
Ethan Furman added the comment: `locals()` returns the dictionary being used (an _EnumDict) and direct assignment uses the `__setitem__` method, which has been overridden -- and it is the only one; so `update()`, etc., still have normal dict meanings and not Enum ones. Next step: compile

[issue34750] locals().update doesn't work in Enum body, even though direct assignment to locals() does

2018-09-20 Thread Antony Lee
New submission from Antony Lee : 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 # -> However, using locals().update(...) doesn't, and silently does the wrong thing: class