qBf㵋C X d Z ddlmZ ddlmZ ddlmZmZ G d dej ZdS )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)Nameparenthesizec e Zd ZdZdZd ZdS ) FixHasKeyTa
anchor=power<
before=any+
trailer< '.' 'has_key' >
trailer<
'('
( not(arglist | argument) arg=any
| arglist<(not argument) arg=any ','>
)
')'
>
after=any*
>
|
negation=not_test<
'not'
anchor=power<
before=any+
trailer< '.' 'has_key' >
trailer<
'('
( not(arglist | argument) arg=any
| arglist<(not argument) arg=any ','>
)
')'
>
>
>
c
J | j }|j j |j k r!| j |j rd S | d }|d }|j }d |d D }|d }| d } | rd | D } |j |j |j |j
|j |j |j
|j fv rt | }t! | dk r |d }nt# j |j | }d
|_ t) dd
}
|r-t) d
d
}t# j |j ||
f }
t# j |j ||
|f }| r:t | }t# j |j |ft- | z }|j j |j |j |j |j |j |j |j |j |j f v rt | }||_ |S )Nnegationanchorc 6 g | ]}| S clone.0ns F/opt/alt/python-internal/lib64/python3.11/lib2to3/fixes/fix_has_key.py
z'FixHasKey.transform..R s 777!''))777 beforeargafterc 6 g | ]}| S r
r r s r r z'FixHasKey.transform..V s ...1QWWYY...r in)prefixnot)symsparenttypenot_testpatternmatchgetr r
comparisonand_testor_testtestlambdefargumentr lenr Nodepowerr comp_optupleexprxor_exprand_expr
shift_expr
arith_exprtermfactor)
selfnoderesultsr r
r r r r r n_opn_notnews
r transformzFixHasKey.transformG s yK
--Lt{++
. 4;;z**"77WX%6777en""$$G$$ /.....E8
dit}N N Ns##Cv;;!AYFF[V44F
D%%% <s+++E;t|eT];;Dk$/Cv+>?? As##C+dj3&5<<*?@@C;DM $
t $ $TZ 9 9 9 s##C
r N)__name__
__module____qualname__
BM_compatiblePATTERNr? r
r r r r &