20.10.20 20:13, Steven D'Aprano пише:
> On Tue, Oct 20, 2020 at 05:30:54PM +0300, Serhiy Storchaka wrote:
> 
>> I do not want to create tens of alternate PEPs with minor variations,
>> and this issue is not worth a PEP. What is your opinion about this? Is
>> it worth to include such optimization? For what kind of variables should
>> it be applied? Should it include global '_'? Should it be merely an
>> optimization (maybe controlled by the -O option) or change in the language?
> 
> Assuming that this actually has a benefit, in either speed or memory, 
> how about this?

And this is a large IF.

> 1. Only eliminate local variables, never globals.
> 
> 2. By default, only variables with a leading underscore are eliminated. 
> This will(?) avoid breaking tests for the debugger etc. that you 
> mentioned.

It is actually what my patch does.

> 3. Under -O, allow more aggressive optimization that eliminates 
> non-underscore variables too.

It is easy to add, but as Guido noted it will break the code that uses
locals(). I though about eliminating underscore variables only with -O.
It would make the feature safer, but even less useful.

> 4. This is an implementation feature, not a language promise. Other 
> interpreters do not have to follow.

It is a question about which I am not sure.

> 5. To be clear, variables are only eliminated if they are assigned to, 
> but never written to:

Yes. And for implementation simplification "del" counts as the use of
the variable. So _ is not eliminated in the following code:

    a, *_ = foo()
    del _
_______________________________________________
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/PW4ZPLM56ELWVJIN4IDFPAQO3PPIMXGG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to