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.