Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E712 Recommendation should be improved #58

Open
sfariaNG opened this issue Oct 25, 2023 · 1 comment
Open

E712 Recommendation should be improved #58

sfariaNG opened this issue Oct 25, 2023 · 1 comment

Comments

@sfariaNG
Copy link

sfariaNG commented Oct 25, 2023

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

@Tom-Finke
Copy link

Tom-Finke commented Nov 7, 2023

I just stumbled upon this because it actually broke my code.
I opened an Issue at Flake8, see PyCQA/flake8#1884

@sfariaNG sfariaNG changed the title E712 Recommendation is incorrect E712 Recommendation should be improved Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants