o bc| @sBdZddlmZddlmZddlmZmZGdddejZdS)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@seZdZdZdZddZdS) FixHasKeyTa anchor=power< before=any+ trailer< '.' 'has_key' > trailer< '(' ( not(arglist | argument) arg=any ','> ) ')' > after=any* > | negation=not_test< 'not' anchor=power< before=any+ trailer< '.' 'has_key' > trailer< '(' ( not(arglist | argument) arg=any ','> ) ')' > > > c Cs|sJ|j}|jj|jkr|j|jrdS|d}|d}|j}dd|dD}|d}|d} | r@dd| D} |j|j |j|j |j |j |j |jfvrWt|}t|d krb|d }nt|j|}d |_td d d } |rtdd d } t|j| | f} t|j || |f} | rt| } t|j| ft| } |jj|j |j|j|j|j|j|j|j|jf vrt| } || _| S)NnegationanchorcSg|]}|qSclone.0nr r 0/usr/lib/python3.10/lib2to3/fixes/fix_has_key.py Rz'FixHasKey.transform..beforeargaftercSr r r r r r rrVr in)prefixnot)symsparenttypenot_testpatternmatchgetrr comparisonand_testor_testtestlambdefargumentrlenrNodepowerrcomp_optupleexprxor_exprand_expr shift_expr arith_exprtermfactor) selfnoderesultsrrrrrrrn_opn_notnewr r r transformGsL        zFixHasKey.transformN)__name__ __module__ __qualname__ BM_compatiblePATTERNr;r r r rr&s rN) __doc__rr fixer_utilrrBaseFixrr r r rs