The variable x is already hoisted out of the loop and y cannot be since it depends on the range() iterator. Running perflint over the code gives loop-invariant-global-usage warnings for both variables:
$ perflint repro.py
************* Module repro
repro.py:3:10: W8202: Lookups of global names within a loop is inefficient, copy to a local variable outside of the loop first. (loop-invariant-global-usage)
repro.py:4:10: W8202: Lookups of global names within a loop is inefficient, copy to a local variable outside of the loop first. (loop-invariant-global-usage)
Given the following code snippet:
The variable
x
is already hoisted out of the loop andy
cannot be since it depends on therange()
iterator. Runningperflint
over the code givesloop-invariant-global-usage
warnings for both variables:This is using
perflint
at commit388d2736
: