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 <1537544456.38.0.956365154283.issue34750@psf.upfronthosting.co.za>
In-reply-to
Content
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 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 collections.abc.MutableMapping 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.
History
Date User Action Args
2018-09-21 15:40:56josh.rsetrecipients: + josh.r, ethan.furman, Antony.Lee
2018-09-21 15:40:56josh.rsetmessageid: <1537544456.38.0.956365154283.issue34750@psf.upfronthosting.co.za>
2018-09-21 15:40:56josh.rlinkissue34750 messages
2018-09-21 15:40:56josh.rcreate