qzo4Pa d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ej ej
ej ej fZ
ed Z ed Zd Zd
ej defdZ G d
de ZdS )z*Comparison checker from the basic checker. N)nodes)utils)
_BasicChecker)HIGH)==!=<>z<=z>=)isis notr r z
builtins.typecallreturnc v t | t j ot | j dk o| j S )z3Is this a call with exactly 1 positional argument ? )
isinstancer Calllenargskeywords)r
s y/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/pylint/checkers/base/comparison_checker.py_is_one_arg_pos_callr s0 dEJ''UC NNa,?U
DUU c e Zd ZdZddddddgifdd d
ddd
Z d)dej dej dej deddf
dZ d)dej dej dej deddf
dZ
dej dej ddfdZdej ddfdZdej ddfdZ
dej ddfdZ ej ddddd d!d" dej ddfd# Zdej ddfd$Zdej d%ej d&ed'ej ddf
d(ZdS )*ComparisonCheckera Checks for comparisons.
- singleton comparison: 'expr == True', 'expr == False' and 'expr == None'
- yoda condition: 'const "comp" right' where comp can be '==', '!=', '<',
'<=', '>' or '>=', and right can be a variable, an attribute, a method or
a function
)Comparison %s should be %ssingleton-comparisonzQUsed when an expression is compared to singleton values like True, False or None.z4Use isinstance() rather than type() for a typecheck.unidiomatic-typecheckzThe idiomatic way to perform an explicit typecheck in Python is to use isinstance(x, Y) rather than type(x) == Y, type(x) is Y. Though there are unusual situations where these give different results. old_names)W0154zold-unidiomatic-typecheck)zBIn '%s', use '%s' when comparing constant literals not '%s' ('%s')literal-comparisonzUsed when comparing an object to a literal, which is usually what you do not want to do, since you can compare to a different literal than what was expected altogether.)zRedundant comparison - %scomparison-with-itselfz/Used when something is compared against itself.)z=Comparison between constants: '%s %s %s' has a constant valuecomparison-of-constantszWhen two literals are compared with each other the result is a constant. Using the constant directly is both easier to read and more performant. Initializing 'True' and 'False' this way is not required since Python 2.3.)z;Comparing against a callable, did you omit the parenthesis?comparison-with-callablezThis message is emitted when pylint detects that a comparison with a callable was made, which might suggest that some parenthesis were omitted, resulting in potential unwanted behaviour.)r nan-comparisonzRUsed when an expression is compared to NaN values like numpy.NaN and float('nan').)C0121C0123R0123R0124R0133W0143W0177F
left_valueright_value root_nodechecking_for_absencer Nc
t j | r
|j |}}n t j | r
|j |}}ndS ddd}|dv rd}ddd} d d
d}
||u}| || | | |t j | s|rdnd
| | | |
| }n@|| | | }| d|d| d|f dS )z=Check if == or != is being used to compare a singleton value.Nz
'{} is {}'z'{} is not {}')FT> FTzB{} if checking for the singleton value {}, or {} if testing for {}znot {}z{}
truthiness falsiness)TFz
'bool({})'z'{}'r 'noder )r is_singleton_constvalueformat as_stringis_test_conditionadd_message)
selfr, r- r. r/ singletonother_valuesingleton_comparison_examplesuggestion_templatetruthiness_exampletruthiness_phrasechecking_truthiness
suggestions
r _check_singleton_comparisonz-ComparisonChecker._check_singleton_comparisonT s #J// %/%5{{II
%k
2
2 %0%6
{IIF/;CS'T'T$
%%T
*2!>!>'3K H H #,3G"G,33,-ABII((**K,A,A,C,C !29== BU LL&&':;BB#--//
""56 JJ" 66JKRR$$&&(=(=(?(? J
".i))++...
;
r c
dt j dt fd dt j dt fd
dt j dt f
fd} || }|s
|| sd S d}|rd}|rd| d | d
}nd| d | d
}| d|d| d|f d S )
Nr5 r c B t | t j rrt | j dk rZ| j d j dk r2| d dk rdS dS # t $ r Y dS w xY w)Nr r nanzbuiltins.floatTF)
r r r r r r7 lowerinferredpytypeAttributeErrorr5 s r
_is_float_nanz>ComparisonChecker._check_nan_comparison.