E712 Recommendation should be improved
sfariaNG opened this issue · 1 comments
Rule E712 says the best practice is using is
when checking a boolean in condition clauses, but according to the document linked in the rule that is not true.
According to https://peps.python.org/pep-0008/#programming-recommendations using is
in a conditional is the "worse" solution. The PEP essentially states:
# Correct:
if greeting:
# Wrong:
if greeting == True:
# Worse:
if greeting is True:
This rule should be updated to make the top solution the first recommendation and additional context added for the alternative since they are not semantically the same. In my experience it is a rare case where you need to explicitly check that the type is boolean, but as it stands right now the recommendation can cause subtle bugs in code with inexperienced developers which is the opposite of the purpose of a linter.
Additional discussion in this issue at pycodestyle: PyCQA/pycodestyle#696
I just stumbled upon this because it actually broke my code.
I opened an Issue at Flake8, see PyCQA/flake8#1884