On Tue, Oct 20, 2020 at 04:26:16PM -0700, Guido van Rossum wrote:

> So this would break many uses of locals(). I'm not sure I like that.

That's a good point I didn't think of.

We could rescue the concept by saying that any reference to locals() 
inside the function disables the elimination, but of course locals can 
be shadowed or aliased, and we can't expect the interpreter to do a full 
analysis of the entire program.


    # Module A
    wibble = locals

    # Module B
    from A import wibble  # this is actually locals
    def func():
        _a = 1
        return wibble()


I think that if there was a big performance gain from elimination, we 
could chalk this up to consenting adults and just say "Don't do anything 
weird!" but if the performance gain is marginal, it probably isn't worth 
the hassle.

On the third hand, and far more speculative, if we had a way of giving 
compiler directives, we could make these sorts of optimizations opt-in 
or opt-out on a fine-grained basis.


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/FUNSE43HYVZG5JROCRMTR4BOLD3CXTDO/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to