Flake8Rules icon indicating copy to clipboard operation
Flake8Rules copied to clipboard

E712 Recommendation should be improved

Open sfariaNG opened this issue 2 years ago • 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: https://github.com/PyCQA/pycodestyle/issues/696

sfariaNG avatar Oct 25 '23 20:10 sfariaNG

I just stumbled upon this because it actually broke my code. I opened an Issue at Flake8, see https://github.com/PyCQA/flake8/issues/1884

Tom-Finke avatar Nov 07 '23 16:11 Tom-Finke