Closed lucascolley closed 2 days ago
Thanks for the report, this is an even simpler case than the one discussed in #9662, for which I would expect any fix to also cover this case. 👍
So it is impossible for msg to be used before assignment - this is a false positive.
Part of the premise that I want to make explicit here is that there are no other reassignments to x
in the middle of the function. x = not x
before the second test at the bottom of the function would violate your example.
Bug description
As per the docs, this works:
but only because we are using the same test,
not x
, twice.If we instead use the test
x
, pylint fails:Command used
Pylint output
Expected behavior
It is impossible for
print("hi")
(or any intervening code that doesn't assign tox
) to change the value ofx
since it is an immutable bool. Ifnot x
isFalse
at the top of the function,x
will always beTrue
at the bottom of the function. So it is impossible formsg
to be used before assignment - this is a false positive.Pylint version