3 \| @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|st|j}|jj|jkr.|jj|jr.dS|jd}|d}|j}dd|dD}|dj }|jd} | rdd| D} |j|j |j|j |j |j |j|jfkrt|}t|d kr|d }ntj|j|}d |_td d d } |rtdd d } tj|j| | f} tj|j || |f} | rBt| } tj|j| ft| } |jj|j |j|j|j|j|j|j|j|jf kr|t| } || _| S)NnegationanchorcSsg|] }|jqS)clone).0nr r 1/usr/lib64/python3.6/lib2to3/fixes/fix_has_key.py Rsz'FixHasKey.transform..beforeargaftercSsg|] }|jqSr )r )r r r r r rVs in)prefixnot)AssertionErrorsymsparenttypeZnot_testpatternmatchgetrr Z comparisonZand_testZor_testZtestZlambdefZargumentrlenrZNodeZpowerrZcomp_optupleexprZxor_exprZand_exprZ shift_exprZ arith_exprZtermZfactor) selfZnodeZresultsrrrrrrrZn_opZn_notnewr r r transformGsF       zFixHasKey.transformN)__name__ __module__ __qualname__Z BM_compatibleZPATTERNr$r r r r r&srN) __doc__rrZ fixer_utilrrZBaseFixrr r r r s