STORE_FAST can also be caused by the assignment to a loop variable, so
STORE/LOAD pairs can come about with things like this:
>>> def f():
... for x in stuff:
... x.work()
...
...
>>> from dis import dis
>>> dis(f)
2 0 LOAD_GLOBAL 0 (stuff)
2 GET_ITER
>> 4 FOR_ITER 6 (to 18)
6 STORE_FAST 0 (x)
3 8 LOAD_FAST 0 (x)
10 LOAD_METHOD 1 (work)
12 CALL_METHOD 0
14 POP_TOP
16 JUMP_ABSOLUTE 2 (to 4)
2 >> 18 LOAD_CONST 0 (None)
20 RETURN_VALUE
I'd guess that they'd be somewhat common in comprehensions too:
>>> dis(x**2 for x in range(1000))
0 GEN_START 0
1 2 LOAD_FAST 0 (.0)
>> 4 FOR_ITER 7 (to 20)
6 STORE_FAST 1 (x)
8 LOAD_FAST 1 (x)
10 LOAD_CONST 0 (2)
12 BINARY_POWER
14 YIELD_VALUE
16 POP_TOP
18 JUMP_ABSOLUTE 2 (to 4)
>> 20 LOAD_CONST 1 (None)
22 RETURN_VALUE
In fact, there's already a bpo issue from 2019:
https://bugs.python.org/issue38381
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/73BMYW3TY7PJB7KRQ3Q3OROGU5UJVJAW/
Code of Conduct: http://python.org/psf/codeofconduct/