qzo4PadZddlZddlmZddlmZddlmZddlmZej ej ej ej fZ edZedZd Zd ejd efd ZGd deZdS)z*Comparison checker from the basic checker.N)nodes)utils) _BasicChecker)HIGH)==!=<>z<=z>=)isis notrrz builtins.typecallreturncvt|tjot|jdko|j S)z3Is this a call with exactly 1 positional argument ?) isinstancerCalllenargskeywords)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_callrs0 dEJ ' ' UC NNa,? U DUUc eZdZdZddddddgifdd d d d d Z d)dejdejdejdeddf dZ d)dejdejdejdeddf dZ dejdejddfdZ dejddfdZ dejddfdZ dejddfdZejddddd d!d"dejddfd#Zdejddfd$Zdejd%ejd&ed'ejddf d(ZdS)*ComparisonCheckeraChecks 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.)rnan-comparisonzRUsed when an expression is compared to NaN values like numpy.NaN and float('nan').)C0121C0123R0123R0124R0133W0143W0177F left_value right_value root_nodechecking_for_absencerNc tj|r |j|}}n tj|r |j|}}ndSddd}|dvrd}ddd} d d d } ||u} ||||||tj|s| rd nd | | || | } n@||||} |d|d|d| fdS)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)ris_singleton_constvalueformat as_stringis_test_condition add_message) selfr,r-r.r/ singleton other_valuesingleton_comparison_examplesuggestion_templatetruthiness_exampletruthiness_phrasechecking_truthiness suggestions r_check_singleton_comparisonz-ComparisonChecker._check_singleton_comparisonTs  #J / / %/%5{{II  %k 2 2 %0%6 {II F/;CS'T'T$  % %T *2!>!> '3K H H #,3G"G ,33,-ABII((**K,A,A,C,C!29== BU LL&&':;BB#--// ""56JJ"66JKRR$$&& (=(=(?(?J  ".i))++... ;      rc dtjdtfd dtjdtfd dtjdtf fd }||}|s ||sdSd}|rd}|rd|d |d }nd|d |d }|d |d|d|f dS) Nr5rcB t|tjrrt|jdkrZ|jdjdkr2|ddkrdSdS#t$rYdSwxYw)Nrrnanzbuiltins.floatTF) rrrrrr7lowerinferredpytypeAttributeErrorr5s r _is_float_nanz>ComparisonChecker._check_nan_comparison.._is_float_nans dEJ//$C NNa4G4G ! *0022e;; MMOOA.5577;KKK#tu!   uu sB B BBct|tjr8|jdkr-t|jtjr|jjdvSdS)NNaN>npnmpnumpyF)rr AttributeattrnameexprNamenamerMs r _is_numpy_nanz>ComparisonChecker._check_nan_comparison.._is_numpy_nansO$00 DT]e5K5Kdi44D9>-CCC5rc0|p |SN)r5rNrYs r_is_nanz8ComparisonChecker._check_nan_comparison.._is_nans" =&&=--*=*= =rznot r3z math.isnan(z)'r$r4)rNodeNGboolr9r;) r<r,r-r.r/r]nan_left absence_textrDrNrYs @@r_check_nan_comparisonz'ComparisonChecker._check_nan_comparisons_               >%, >4 > > > > > > >7:&&  4 4  F  "!L  QQ\QQk6K6K6M6MQQQJJP\PPj6J6J6L6LPPPJ  .i))++... ;      rliteralr5ct|tjtjtjf}d}t|tjrPt|jts|jdSt|jttttf}|s|r[| }d|vrd}d}nd}d}| ||}|d||||f|tdSdS) zMCheck if we compare to a literal, which is usually what we do not want to do.FNr rrr r )rr5 confidence)rrListDictSetConstr7r`bytesstrintfloatr9replacer;r) r<rdr5is_other_literalis_constincorrect_node_strequal_or_not_equal is_or_is_notfixed_node_strs r_check_literal_comparisonz+ComparisonChecker._check_literal_comparisons#&g EJ /RSS gu{ + + K'-.. '-2G!'-%c51IJJH  ' !%!1!1 ---%)"' %)"# /770N   $&& "          rc|j}|jdd}|jdd}t|tjr)t|tjr|j}|j}nBt|tjr(t|tjr|j}|j}||kr%|d|d|}|d||fdSdS)zCheck if identifier is compared against itself. :param node: Compare node :Example: val = 786 if val == val: # [comparison-with-itself] pass rr r!r4N) leftopsrrrjr7rWrXr;)r<r5 left_operand right_operandoperatorrDs r_check_logical_tautologyz*ComparisonChecker._check_logical_tautologysy  A 8A;q> lEK 0 0 /Z 5;6 6 /(-L)/MM  ej 1 1 /j 5:7 7  /(,L).M = ( ((EE8EEmEEJ   5D }  U U U U U ) (rc&|j}t|tjsdS|jdd}t|tjsdS|jdd}|d||j||jftdS)zGWhen two constants are being compared it is always a logical tautology.Nrrr")r5rrf)ryrrrjrzr;r7r)r<r5r{r|r}s r_check_constants_comparisonz-ComparisonChecker._check_constants_comparisonsy , 44  F A -55  F8A;q>  %$h 0CD      rc|jdd}|tvrdStjtjf}|j|jdd}}d}||fD]_}tj|}t||r9d| vr#td|j Ds|dz }`|dkr| d|dSdS)Nrrztyping._SpecialFormc3JK|]}t|tjVdSr[)rrRaise).0xs r z?ComparisonChecker._check_callable_comparison..s.NN1Jq%+66NNNNNNrr#rM)rzCOMPARISON_OPERATORSr FunctionDefastroid BoundMethodryr safe_inferrdecoratornamesanybodyr;) r<r5r}bare_callablesr{r|number_of_bare_callablesoperandrJs r_check_callable_comparisonz,ComparisonChecker._check_callable_comparison s8A;q> / / / F+W-@A&*i!Qm $% #]2 . .G'00H8^44 .)1H1H1J1JJJNN NNNNNK)A-( #q ( (   7d  C C C C C ) (rrr r!r"r#r$c||||||||t |jdkrdS|j}|jd\}}|dvr|||||dk|dvr|||||dv|dvr| ||dSdS) Nrr>rrr)r/>r rrr >rr >r r ) rr~_check_unidiomatic_typecheckrrrzryrErcrv)r<r5ryr}rights r visit_comparezComparisonChecker.visit_compare s& ''--- %%d+++ ))$/// ((... tx==A   Fy(1+% | # #  , ,eTD8H -    3 3 3  & &eTDT8T '    ' ' '  * *5$ 7 7 7 7 7 ( 'rc|jd\}}|tvr0|j}t|r|||||dSdSdS)Nr)rzTYPECHECK_COMPARISON_OPERATORSryr_check_type_x_is_y)r<r5r}rrys rrz.ComparisonChecker._check_unidiomatic_typecheckBsi(1+% 5 5 59D#D)) E''dHeDDDDD 6 5 E Erryr}rc tj|j}t|tjr|tksdS|dvrt|rtj|j}t|tjrS|tkr6tj|j d}t|tsdS| d|dS)z(Check for expressions like type(x) == Y.N>r r rrrM) rrfuncrrClassDefqname TYPE_QNAMErrLITERAL_NODE_TYPESr;)r<r5ryr}r left_func right_func right_args rrz$ComparisonChecker._check_type_x_is_yIs$TY// y%. 1 1 6?oo6G6G:6U6U F ' ' ',@,G,G ')%*55J:u~66 $$&&*44",UZ];; !)-?@@F 0t<<<<rs 10!!!!!!<<<<<<""""""k5:uz59E y!CDD!*+G!H!H  Vu|VVVVV I=I=I=I=I= I=I=I=I=I=r