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

The simplifiable-if-expression message description should not only mention bool(test) #5882

Closed
LefterisJP opened this issue Mar 9, 2022 · 3 comments · Fixed by #6574
Closed

Comments

@LefterisJP
Copy link
Contributor

Bug description

Here is a simple example

"""Simplifiable if expression false positive"""

TEST_VAR1 = True
TEST_VAR2 = 'True'
A = True if TEST_VAR1 is True else False
B = True if TEST_VAR2 == 'True' else False

Configuration

No response

Command used

pylint test.py

Pylint output

************* Module test2
test2.py:5:4: R1719: The if expression can be replaced with 'test' (simplifiable-if-expression)
test2.py:6:4: R1719: The if expression can be replaced with 'test' (simplifiable-if-expression)

Expected behavior

I would only expect the first simplifiable-if-expression warning for A.

For B simplifying it would not work since it's comparing against the string True and eventually the string False and bool(string) is always True

Pylint version

pylint 2.12.2
astroid 2.9.0
Python 3.9.10 (main, Feb  3 2022, 16:04:33) 
[GCC 11.1.0]

OS / Environment

Linux 5.16.12-arch1-1 #1 SMP PREEMPT Wed, 02 Mar 2022 12:22:51 +0000 x86_64 GNU/Linux

Additional dependencies

No response

@LefterisJP LefterisJP added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Mar 9, 2022
@DanielNoord
Copy link
Collaborator

@LefterisJP Can't you write:

B = TEST_VAR2 == 'True'

@LefterisJP
Copy link
Contributor Author

@LefterisJP Can't you write:

B = TEST_VAR2 == 'True'

yes indeed, but what I understood for simplifiable-if-expression was telling me to use bool(): https://vald-phoenix.github.io/pylint-errors/plerr/errors/refactoring/R1719.html

Perhaps I misunderstood the error then?

@DanielNoord
Copy link
Collaborator

Ah, it seems like that information is incorrect. We should update the description of that message.
I'll change the issue title to reflect this. Thanks for telling us about this!

Btw: That project (although helpful) is not the "official" pylint documentation. The official documentation can be found here: https://pylint.pycqa.org/en/latest/messages/refactor/simplifiable-if-expression.html.
We have been working on integrating that project and the code examples into our own documentation, see #5527

@DanielNoord DanielNoord changed the title False positive simplifiable if expression for stringified bool The simplifiable-if-expression message description should not only mention bool(test) Mar 9, 2022
@DanielNoord DanielNoord added Documentation 📗 and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Mar 9, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue May 11, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue May 11, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue May 12, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue May 29, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue May 29, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue May 29, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue May 29, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue May 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants