On Tue, Aug 21, 2018 at 2:16 AM, Chris Barker via Python-ideas <python-ideas@python.org> wrote: > On Mon, Aug 20, 2018 at 7:21 AM, Steven D'Aprano <st...@pearwood.info> > wrote: >> >> * Introducing a warning makes it clear that this is not a de facto >> language standard, but a mere implementation detail subject to >> change if somebody comes up with a better optimization for locals. > > > defacto standards are sub-optimum -- the docs say "may not" -- that seems > really sketchy to me. > > Even if there is no change to the implementation of cPython, I'd like to see > the behavior clearly defined -- if I pass a object returned by "locals()" to > a function, and that function modifies that object -- will, or will not, the > local namespace be altered? Saying it "may" be altered is kind of crazy! > Does that mean the same code will have a different effect if run in two > different (compliant) implementations of Python? That sure seems like a bad > idea...
If you do the wrong thing, a compliant Python is allowed to do one of two things. It's no different from anything else that's been defined as the wrong thing - opening a file and then dropping it on the floor (might close it promptly, might not), testing integers by identity ("x is 5"), etc, etc. The language is well-enough-defined that you can be confident that locals()["x"]=1 will EITHER change x to 1 OR have no significant effect. If you truly want to mandate that every Python implementation absolutely perfectly imitate CPython, what is the point of other implementations? Or a language spec? They'd just be refactorings of CPython. ChrisA _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/