
    yIf26                         d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ej	        ej
        ej        ej        fZ ed          Z ed          Zd	Zd
ej        defdZ G d de          ZdS )z*Comparison checker from the basic checker.    N)nodes)utils)_BasicChecker)HIGH)==!=<>z<=z>=)isis notr   r   zbuiltins.typecallreturnc                 v    t          | t          j                  ot          | j                  dk    o| j         S )z3Is this a call with exactly 1 positional argument ?   )
isinstancer   Calllenargskeywords)r   s    [/var/www/piapp/venv/lib/python3.11/site-packages/pylint/checkers/base/comparison_checker.py_is_one_arg_pos_callr      s0    dEJ''UC	NNa,?UDUU    c                      e Zd ZdZddddddgifdd	d
dddZ	 d)dej        dej        dej        deddf
dZ		 d)dej        dej        dej        deddf
dZ
dej        dej        ddfdZdej        ddfdZdej        ddfdZdej        ddfdZ ej        ddddd d!d"          dej        ddfd#            Zdej        ddfd$Zdej        d%ej        d&ed'ej        ddf
d(ZdS )*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 %ssingleton-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)W0154zold-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.)zRedundant comparison - %scomparison-with-itselfz/Used when something is compared against itself.)z=Comparison between constants: '%s %s %s' has a constant valuecomparison-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').)C0121C0123R0123R0124R0133W0143W0177F
left_valueright_value	root_nodechecking_for_absencer   Nc           
         t          j        |          r
|j        |}}n t          j        |          r
|j        |}}ndS ddd}|dv rd}ddd}	d	d
d}
||u}|                    ||                             |                                |                                          |t          j        |          s|rdnd                    |	|                             |                                                    |
|                   }n@||                             |                                |                                          }|                     d|d|                                 d|f           dS )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 {}znot {}z{}
truthiness	falsiness)TFz
'bool({})'z'{}'r   'noder   )r   is_singleton_constvalueformat	as_stringis_test_conditionadd_message)selfr,   r-   r.   r/   	singletonother_valuesingleton_comparison_examplesuggestion_templatetruthiness_exampletruthiness_phrasechecking_truthiness
suggestions                r   _check_singleton_comparisonz-ComparisonChecker._check_singleton_comparisonT   s    #J// 	%/%5{{II%k22 	%0%6
{IIF/;CS'T'T$ %%T   *2!>!>'3K H H #,3G"G,33,-ABII((**K,A,A,C,C   !29== BU LL&&':;BB#--//  
 ""56 JJ" 66JKRR$$&&(=(=(?(? J 	".i))++...
; 	 	
 	
 	
 	
 	
r   c                   	
 dt           j        dt          fd	dt           j        dt          fd
dt           j        dt          f	
fd} ||          }|s ||          sd S d}|rd}|rd| d	|                                 d
}nd| d	|                                 d
}|                     d|d|                                 d|f           d S )Nr5   r   c                 B   	 t          | t          j                  rrt          | j                  dk    rZ| j        d         j                                        dk    r2|                                 d                                         dk    rdS dS # t          $ r Y dS w xY w)Nr   r   nanzbuiltins.floatTF)
r   r   r   r   r   r7   lowerinferredpytypeAttributeErrorr5   s    r   _is_float_nanz>ComparisonChecker._check_nan_comparison.<locals>._is_float_nan   s    	dEJ// $C	NNa4G4G	!*0022e;; MMOOA.5577;KKK#tu!   uus   B
B 
BBc                     t          | t          j                  r8| j        dk    r-t          | j        t          j                  r| j        j        dv S dS )NNaN>   npnmpnumpyF)r   r   	AttributeattrnameexprNamenamerM   s    r   _is_numpy_nanz>ComparisonChecker._check_nan_comparison.<locals>._is_numpy_nan   sO    $00 DT]e5K5Kdi44 D9>-CCC5r   c                 0     |           p
 |           S N )r5   rN   rY   s    r   _is_nanz8ComparisonChecker._check_nan_comparison.<locals>._is_nan   s"     =&&=--*=*==r    znot r3   zmath.isnan(z)'r$   r4   )r   NodeNGboolr9   r;   )r<   r,   r-   r.   r/   r]   nan_leftabsence_textrD   rN   rY   s            @@r   _check_nan_comparisonz'ComparisonChecker._check_nan_comparison   s_   
	 
	 
	 
	 
	 
		 	 	 	 	 		>%, 	>4 	> 	> 	> 	> 	> 	> 	> 7:&& 	 4 4 	F 	"!L 	QQ\QQk6K6K6M6MQQQJJP\PPj6J6J6L6LPPPJ.i))++...
; 	 	
 	
 	
 	
 	
r   literalr5   c                    t          |t          j        t          j        t          j        f          }d}t          |t          j                  rPt          |j        t                    s|j        dS t          |j        t          t          t          t          f          }|s|r[|                                }d|v rd}d}nd}d}|                    ||          }|                     d||||f|t                     dS dS )	zMCheck if we compare to a literal, which is usually what we do not want to do.FNr   r   r   r   r    )r   r5   
confidence)r   r   ListDictSetConstr7   r`   bytesstrintfloatr9   replacer;   r   )	r<   rd   r5   is_other_literalis_constincorrect_node_strequal_or_not_equalis_or_is_notfixed_node_strs	            r   _check_literal_comparisonz+ComparisonChecker._check_literal_comparison   s#    &g
EJ	/RSSgu{++ 	K'-.. '-2G!'-%c51IJJH 	' 	!%!1!1---%)"'%)"#/770 N $&& "	   
 
 
 
 
	 	r   c                    |j         }|j        d         d         }|j        d         d         }t          |t          j                  r)t          |t          j                  r|j        }|j        }nBt          |t          j                  r(t          |t          j                  r|j        }|j        }||k    r%| d| d| }|                     d||f           dS dS )zCheck if identifier is compared against itself.

        :param node: Compare node
        :Example:
        val = 786
        if val == val:  # [comparison-with-itself]
            pass
        r   r    r!   r4   N)	leftopsr   r   rj   r7   rW   rX   r;   )r<   r5   left_operandright_operandoperatorrD   s         r   _check_logical_tautologyz*ComparisonChecker._check_logical_tautology   s     yA8A;q>lEK00 		/Z5;6
 6
 		/ (-L)/MMej11 	/j5:7
 7
 	/ (,L).M=(((EE8EEmEEJ5D
}UUUUU )(r   c                 &   |j         }t          |t          j                  sdS |j        d         d         }t          |t          j                  sdS |j        d         d         }|                     d||j        ||j        ft                     dS )zGWhen two constants are being compared it is always a logical tautology.Nr   r   r"   )r5   r   rf   )ry   r   r   rj   rz   r;   r7   r   )r<   r5   r{   r|   r}   s        r   _check_constants_comparisonz-ComparisonChecker._check_constants_comparison   s    y,44 	FA-55 	F8A;q>%$h0CD	 	 	
 	
 	
 	
 	
r   c                    |j         d         d         }|t          vrd S t          j        t          j        f}|j        |j         d         d         }}d}||fD ]_}t          j        |          }t          ||          r9d|
                                vr#t          d |j        D                       s|dz  }`|dk    r|                     d|           d S d S )Nr   r   ztyping._SpecialFormc              3   J   K   | ]}t          |t          j                  V  d S r[   )r   r   Raise).0xs     r   	<genexpr>z?ComparisonChecker._check_callable_comparison.<locals>.<genexpr>  s.      NN1Jq%+66NNNNNNr   r#   rM   )rz   COMPARISON_OPERATORSr   FunctionDefastroidBoundMethodry   r   
safe_inferr   decoratornamesanybodyr;   )	r<   r5   r}   bare_callablesr{   r|   number_of_bare_callablesoperandrJ   s	            r   _check_callable_comparisonz,ComparisonChecker._check_callable_comparison	  s   8A;q>///F+W-@A&*i!Qm $% #]2 		. 		.G'00H 8^44.)1H1H1J1JJJNNNNNNN K )A-(#q((7dCCCCC )(r   r   r    r!   r"   r#   r$   c                    |                      |           |                     |           |                     |           |                     |           t	          |j                  dk    rd S |j        }|j        d         \  }}|dv r|                     ||||dk               |dv r|                     ||||dv            |dv r| 	                    ||           d S d S )	Nr   r   >   r   r   r   )r/   >   r   r   r   r   >   r   r   >   r   r   )
r   r~   _check_unidiomatic_typecheckr   r   rz   ry   rE   rc   rv   )r<   r5   ry   r}   rights        r   visit_comparezComparisonChecker.visit_compare   s&    	''---%%d+++))$///((... tx==AFy(1+%|##,,eTD8H -    333&&eTDT8T '    '''**5$77777 ('r   c                     |j         d         \  }}|t          v r0|j        }t          |          r|                     ||||           d S d S d S )Nr   )rz   TYPECHECK_COMPARISON_OPERATORSry   r   _check_type_x_is_y)r<   r5   r}   r   ry   s        r   r   z.ComparisonChecker._check_unidiomatic_typecheckB  si    (1+%5559D#D)) E''dHeDDDDD 65E Er   ry   r}   r   c                 
   t          j        |j                  }t          |t          j                  r|                                t          k    sdS |dv rt          |          rt          j        |j                  }t          |t          j                  rS|                                t          k    r6t          j        |j	        d                   }t          |t                    sdS |                     d|           dS )z(Check for expressions like type(x) == Y.N>   r   r   r   r   rM   )r   r   funcr   r   ClassDefqname
TYPE_QNAMEr   r   LITERAL_NODE_TYPESr;   )r<   r5   ry   r}   r   	left_func
right_func	right_args           r   r   z$ComparisonChecker._check_type_x_is_yI  s     $TY//	y%.11	6?oo6G6G:6U6UF''',@,G,G')%*55J:u~66$$&&*44 ",UZ];;	!)-?@@ F0t<<<<<r   )F)__name__
__module____qualname____doc__msgsr   r_   Comparer`   rE   rc   rv   r~   r   r   r   only_required_for_messagesr   r   rl   r   r\   r   r   r   r      s        
 C#= ABC






U0 0Dn &+6
 6
L6
 \6
 =	6

 #6
 
6
 6
 6
 6
z &++
 +
L+
 \+
 =	+

 #+
 
+
 +
 +
 +
Z!|!+0=!	! ! ! !FVU] Vt V V V V6
 
$ 
 
 
 
$Du} D D D D D. &U% !" 8%- 8D 8 8 8 82E E4 E E E E=m= l= 	=
 |= 
= = = = = =r   r   )r   r   r   pylint.checkersr   "pylint.checkers.base.basic_checkerr   pylint.interfacesr   rj   rh   rg   ri   r   	frozensetr   r   r   r_   r`   r   r   r\   r   r   <module>r      s  
 1 0        ! ! ! ! ! ! < < < < < < " " " " " "k5:uz59E  y!CDD !*+G!H!H 
Vu| V V V V V
I= I= I= I= I= I= I= I= I= I=r   