Pylint does not detect undefined variable in 'else' clause

I have the following python code

a = 2
if a == 1:
    b = 'blah'
    print b
else:
    print b

When I try to run it, I get a runtime error, since "b" is defined only in the "if" section, not the "else" section.

Pylint and Pyflakes were both unable to detect this problem.

Is there any other way to detect it without running the code?

+4
source share
1 answer

, , , . , if - else , - , , b ? , ( , , ), . . .

+2

All Articles