Extend test cases for 'condition-evals-to-constant' (#8721)

Related to #7933.

The original issue reported pylint as missing bugs in comparisons
like:

`if get_text() == "string A" or "string B":`

In reality this is already covered by the message
'condition-evals-to-constant', however test cases with strings
were missing, they have been added to self-document other cases
this checker applies to and extend coverage.
This commit is contained in:
Antonio 2023-05-29 05:47:05 -06:00 committed by GitHub
parent c5f3ff4c37
commit 8cdccbbe73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -44,3 +44,10 @@ if True: # pylint: disable=using-constant-test
CONSTANT or True
bool(CONSTANT or OTHER)
bool(func(CONSTANT or True))
# Strings also evaluate as True (they are constants)
if func("a") == "b" or "c": # [condition-evals-to-constant]
pass
if 1 == func(2) or "fermi": # [condition-evals-to-constant]
pass

View File

@ -13,3 +13,5 @@ condition-evals-to-constant:33:7:33:19::Boolean condition 'True or True' will al
condition-evals-to-constant:34:7:34:21::Boolean condition 'False or False' will always evaluate to 'False':UNDEFINED
condition-evals-to-constant:35:7:35:20::Boolean condition 'True and True' will always evaluate to 'True':UNDEFINED
condition-evals-to-constant:36:7:36:22::Boolean condition 'False and False' will always evaluate to 'False':UNDEFINED
condition-evals-to-constant:49:3:49:26::Boolean condition 'func('a') == 'b' or 'c'' will always evaluate to ''c'':UNDEFINED
condition-evals-to-constant:52:3:52:26::Boolean condition '1 == func(2) or 'fermi'' will always evaluate to ''fermi'':UNDEFINED