Skip to content

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

@LefterisJP

Description

@LefterisJP

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions