I doubted whether or not to write, but since Guido has already touched a similar topic (see "Live variable analysis -> earlier release"), so will I write.

It is common to assign some values which are never used to variables because the syntax demands this. For example:

    head, _, rest = path.partition('/')
    first, second, *_ = line.split()
    for _ in range(10): ...
    [k for k, _ in pairs]

What if make such assignments no-op? It will only work with some limitations:

1. The variable is local. Not global, not nonlocal, not cell.
2. The variable name must start with '_'. Otherwise there would be larger risk of breaking a legal code which uses locals() with str.format() or like. 3. "del" is considered a use of the variable. So explicitly deleted variables will not be optimized out. 4. Star-assignment still consumes the iterator. It just might not to keep all values in memory.

STORE_FAST will be replaced with POP_TOP in these cases.

I wrote some code few weeks ago, and it is not too complex. My doubts are only that the benefit of the optimization with the above limitations is very restricted.
_______________________________________________
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/PH7R2R3FTLT3I734FTTSN57P4PKUZ7L7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to