o
    Š�bc|  ã                   @   sB   d Z ddlmZ ddlmZ ddlmZmZ G dd„ dejƒZdS )a&  Fixer for has_key().

Calls to .has_key() methods are expressed in terms of the 'in'
operator:

    d.has_key(k) -> k in d

CAVEATS:
1) While the primary target of this fixer is dict.has_key(), the
   fixer will change any has_key() method call, regardless of its
   class.

2) Cases like this will not be converted:

    m = d.has_key
    if m(k):
        ...

   Only *calls* to has_key() are converted. While it is possible to
   convert the above to something like

    m = d.__contains__
    if m(k):
        ...

   this is currently not done.
é   )Úpytree)Ú
fixer_base)ÚNameÚparenthesizec                   @   s   e Zd ZdZdZdd„ ZdS )Ú	FixHasKeyTa•  
    anchor=power<
        before=any+
        trailer< '.' 'has_key' >
        trailer<
            '('
            ( not(arglist | argument<any '=' any>) arg=any
            | arglist<(not argument<any '=' any>) arg=any ','>
            )
            ')'
        >
        after=any*
    >
    |
    negation=not_test<
        'not'
        anchor=power<
            before=any+
            trailer< '.' 'has_key' >
            trailer<
                '('
                ( not(arglist | argument<any '=' any>) arg=any
                | arglist<(not argument<any '=' any>) arg=any ','>
                )
                ')'
            >
        >
    >
    c              
   C   s€  |sJ ‚| j }|jj|jkr| j |j¡rd S | d¡}|d }|j}dd„ |d D ƒ}|d  ¡ }| d¡}	|	r@dd„ |	D ƒ}	|j|j	|j|j
|j|j|j|jfv rWt|ƒ}t|ƒd	krb|d
 }nt |j|¡}d|_tddd�}
|rƒtddd�}t |j||
f¡}
t |j	||
|f¡}|	rŸt|ƒ}t |j|ft|	ƒ ¡}|jj|j	|j|j|j|j|j|j|j|jf	v r»t|ƒ}||_|S )NÚnegationÚanchorc                 S   ó   g | ]}|  ¡ ‘qS © ©Úclone©Ú.0Únr
   r
   ú0/usr/lib/python3.10/lib2to3/fixes/fix_has_key.pyÚ
<listcomp>R   ó    z'FixHasKey.transform.<locals>.<listcomp>ÚbeforeÚargÚafterc                 S   r	   r
   r   r   r
   r
   r   r   V   r   é   é    ú Úin)ÚprefixÚnot)ÚsymsÚparentÚtypeÚnot_testÚpatternÚmatchÚgetr   r   Ú
comparisonÚand_testÚor_testÚtestÚlambdefÚargumentr   Úlenr   ÚNodeÚpowerr   Úcomp_opÚtupleÚexprÚxor_exprÚand_exprÚ
shift_exprÚ
arith_exprÚtermÚfactor)ÚselfÚnodeÚresultsr   r   r   r   r   r   r   Ún_opÚn_notÚnewr
   r
   r   Ú	transformG   sL   ÿ

ÿ
ýzFixHasKey.transformN)Ú__name__Ú
__module__Ú__qualname__ÚBM_compatibleÚPATTERNr;   r
   r
   r
   r   r   &   s    r   N)	Ú__doc__Ú r   r   Ú
fixer_utilr   r   ÚBaseFixr   r
   r
   r
   r   Ú<module>   s
   