чт, 16 авг. 2018 г. в 22:37, Chris Barker via Python-ideas < python-ideas@python.org>:
> > I wonder why locals doesn't return a Mapping Proxy, or other read-only > mapping object? > > If it's not guaranteed to be THE locals dict, and changes *may* not affect > the real one (but may), a read-only object seems like much safer idea. > > -CHB > > I have the same feeling and already have asked the same question before https://mail.python.org/pipermail/python-list/2018-February/731241.html. The main take away was that it is the CPython implementation detail and that `MappingProxy` type was introduced only in 3.3. I still do not find these arguments convincing. On the other hand with the current status quo - `locals` returns `dict` inside a function, we have only advantages: a) `locals` always returns a dict and is consistent in all places. (To be consistent is always good.) b) This type of question occurs every 6 months (there is always a topic to talk about at ML). c) When someone encounters this behavior first time, he thinks that he found a bug <- There was no error but nothing happened (gives an opportunity to study the internal details of the CPython implementation, the average level increases. Everyone also tries to find a way, something like "I believe, there must be a way, because Python is so dynamic" which theoretically allows you to make even more new discoveries.). d) This is considered by some as a way not to leak the CPython implementation details. (Here I have no comments, let it be on the conscience of others.) e) It leaves a room for a future changes (In fact, in some situations I would like to have this possibility). But if seriously, I think that the present situation is pretty weird especially when there is already the `MappingProxy` type. When it's not allowed and does not work (I'm only talking about the functions), it's better to raise early, instead of be silent until the last. With kind regards, -gdg
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/