
    e                        d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 erd dl
mZ  ed      Z ed      Z ed	      Z G d
 de      ZddZy)    )annotations)TYPE_CHECKING)nodes)BaseChecker)HIGH)PyLinter)<z<=>z>=z!=z==)iszis not)inznot inc                  ,    e Zd ZdZdZddiZddZd	dZy)
BadChainedComparisonCheckerz5Checks for unintentional usage of chained comparison.bad-chained-comparisonW3601)zTSuspicious %s-part chained comparison using semantically incompatible operators (%s)r   zUsed when there is a chained comparison where one expression is part of two comparisons that belong to different semantic groups ("<" does not mean the same thing as "is", chaining them in "0 < x is None" is probably a mistake).c                n    t         t        t        fD ]  }|d   |v s| t        fd|D               S )Nr   c              3  &   K   | ]  }|v  
 y wN ).0ogroups     H/usr/lib/python3/dist-packages/pylint/checkers/bad_chained_comparison.py	<genexpr>zHBadChainedComparisonChecker._has_diff_semantic_groups.<locals>.<genexpr>*   s     5aqEz5s   )COMPARISON_OPIDENTITY_OPMEMBERSHIP_OPall)self	operatorssemantic_groupr   s      @r   _has_diff_semantic_groupsz5BadChainedComparisonChecker._has_diff_semantic_groups%   s@    ,k=I 	'N|~-&	' 595555    c                *   t        |j                  D ch c]  }|d   	 c}      }| j                  |      rWt        |j                         }dj	                  d |d d D              d|d    dz   }| j                  d|||ft               y y c c}w )	Nr   z, c              3  (   K   | ]
  }d | d   yw)'Nr   )r   r   s     r   r   z<BadChainedComparisonChecker.visit_compare.<locals>.<genexpr>1   s     ;qAaS(;s   z and 'r%   r   )nodeargs
confidence)sortedopsr!   lenjoinadd_messager   )r   r'   opr   	num_partsincompatibless         r   visit_comparez)BadChainedComparisonChecker.visit_compare,   s    DHH5bBqE56	)))4txx=/I		;IcrN;;yQS}oUV>WW  (/	   5 6s   BN)r   z	list[str]returnbool)r'   znodes.Comparer3   None)__name__
__module____qualname____doc__namemsgsr!   r2   r   r"   r   r   r      s#    ?#D 
	D6r"   r   c                8    | j                  t        |              y r   )register_checkerr   )linters    r   registerr?   ;   s    
7?@r"   N)r>   r   r3   r5   )
__future__r   typingr   astroidr   pylint.checkersr   pylint.interfacesr   pylint.lintr   	frozensetr   r   r   r   r?   r   r"   r   <module>rG      sP   
 #    ' "$<=()*+"+ "JAr"   