Viewing File: /opt/alt/python35/lib64/python3.5/lib2to3/fixes/__pycache__/fix_has_key.cpython-35.pyc



¯ÕYf–ã@sidZddlmZddlmZddlmZddlmZmZGdd„dej	ƒZ
dS)	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)Útoken)Ú
fixer_base)ÚNameÚparenthesizec@s(eZdZdZdZdd„ZdS)Ú	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

Cs.|st‚|j}|jj|jkrC|jj|jƒrCdS|jdƒ}|d}|j}dd„|dDƒ}|dj	ƒ}|jdƒ}	|	r´dd„|	Dƒ}	|j|j
|j|j|j|j
|j|jfkrùt|ƒ}t|ƒd	kr|d
}ntj|j|ƒ}d|_tdd
dƒ}
|r{tdd
dƒ}tj|j||
fƒ}
tj|j
||
|fƒ}|	rÍt|ƒ}tj|j|ft|	ƒƒ}|jj|j
|j|j|j|j|j|j|j|jf	kr!t|ƒ}||_|S)NÚnegationÚanchorcSsg|]}|jƒ‘qS©)Úclone)Ú.0Únr
r
ú>/opt/alt/python35/lib64/python3.5/lib2to3/fixes/fix_has_key.pyú
<listcomp>Ss	z'FixHasKey.transform.<locals>.<listcomp>ÚbeforeÚargÚaftercSsg|]}|jƒ‘qSr
)r)rr
r
r
rrWs	ééú ÚinÚprefixÚnot)ÚAssertionErrorÚsymsÚparentÚtypeZnot_testÚpatternÚmatchÚgetrrZ
comparisonZand_testZor_testZtestZlambdefZargumentrÚlenrZNodeZpowerrZcomp_opÚtupleÚexprZxor_exprZand_exprZ
shift_exprZ
arith_exprZtermZfactor)
ÚselfZnodeZresultsrrr	rrrrZn_opZn_notÚnewr
r
rÚ	transformHsF	
	!
	"	zFixHasKey.transformN)Ú__name__Ú
__module__Ú__qualname__Z
BM_compatibleZPATTERNr%r
r
r
rr'srN)Ú__doc__ÚrZpgen2rrZ
fixer_utilrrZBaseFixrr
r
r
rÚ<module>s

Back to Directory File Manager