[Python-ideas] Jump to function as an an alternative to call function

Chris Angelico rosuav at gmail.com
Mon Aug 20 14:16:51 EDT 2018


On Tue, Aug 21, 2018 at 2:16 AM, Chris Barker via Python-ideas
<python-ideas at python.org> wrote:
> On Mon, Aug 20, 2018 at 7:21 AM, Steven D'Aprano <steve at 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


More information about the Python-ideas mailing list