This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author josh.r
Recipients Antony.Lee, ethan.furman, josh.r
Date 2018-09-21.15:40:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The documentation for 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 interpreter. 

The docstring for locals is similar, making it clear that any correlation between the returned dict and the state of locals if *either* is subsequently modified is implementation dependent, subject to change without back-compat concerns; even if we made this change, we've given ourselves the freedom to undo it at any time, which makes it useless to anyone who might try to rely on it.

The fact that even locals()["a"] = 1 happens to work is an implementation detail AFAICT; normally, locals() is and should remain read-only (or at least, modifications don't actually affect the local scope aside from the dict returned by locals()).

I'm worried that making _EnumDict inherit from in general would slow down Enums (at the very least creation, I'm not clear on whether _EnumDict remains, hidden behind the mappingproxy, for future lookups on the class), since MutableMapping would introduce a Python layer of overhead to most calls.

I'm also just not inclined to encourage the common assumption that locals() returns a dict where mutating it actually works, since it usually doesn't.
Date User Action Args
2018-09-21 15:40:56josh.rsetrecipients: + josh.r, ethan.furman, Antony.Lee
2018-09-21 15:40:56josh.rsetmessageid: <>
2018-09-21 15:40:56josh.rlinkissue34750 messages
2018-09-21 15:40:56josh.rcreate