"Redeclared s defined above without usage"
<pre><code>for i in range(10):
    s = 5
    for j in range(10):
        s = min(s)
</code></pre>

<p>The above code gives the title of this question as warning in IntelliJ for the second line.</p>

<p>I'm pretty sure that the warning happens because in the CFG there are possibly two consecutive writes (without read in between) to <code>s</code> because of the nested loops. Until now I have been ignoring the warning but to be on the safe side I'd like to ask for confirmation of my hypothesis.</p>

<p>Your hypothesis is nearly correct. The name <code>s</code> was bounded to an integer whose value was never used nor changed in the enclosing loop and yet it is rebounded to another value (<em>although that will raise an error</em>) in the nested loop. Note that the first assignment does not change with any iteration of the outer <code>for</code> loop.</p>

<p>The IDE's warning suggests the first assignment inside the loop is unnecessary as <code>s</code> was never changed. The assignment might as well have been better placed outside the <code>for</code> loop which will prevent a redundant binding and rebinding:</p>

<pre><code>s = 5
for i in range(10):
    ...
</code></pre>

python intellij-idea