ðÕYf ã@smdZddlmZddlmZmZmZmZmZm Z dZ dZ Gdd„dej ƒZ dS) aÜAdjust some old Python 2 idioms to their modern counterparts. * Change some type comparisons to isinstance() calls: type(x) == T -> isinstance(x, T) type(x) is T -> isinstance(x, T) type(x) != T -> not isinstance(x, T) type(x) is not T -> not isinstance(x, T) * Change "while 1:" into "while True:". * Change both v = list(EXPR) v.sort() foo(v) and the more general v = EXPR v.sort() foo(v) into v = sorted(EXPR) foo(v) é)Ú fixer_base)ÚCallÚCommaÚNameÚNodeÚ BlankLineÚsymsz0(n='!=' | '==' | 'is' | n=comp_op< 'is' 'not' >)z(power< 'type' trailer< '(' x=any ')' > >csneZdZdZdeeeefZ‡fdd†Zdd„Zdd„Z d d „Z d d „Z ‡S) Ú FixIdiomsTaº isinstance=comparison< %s %s T=any > | isinstance=comparison< T=any %s %s > | while_stmt< 'while' while='1' ':' any+ > | sorted=any< any* simple_stmt< expr_stmt< id1=any '=' power< list='list' trailer< '(' (not arglist) any ')' > > > '\n' > sort= simple_stmt< power< id2=any trailer< '.' 'sort' > trailer< '(' ')' > > '\n' > next=any* > | sorted=any< any* simple_stmt< expr_stmt< id1=any '=' expr=any > '\n' > sort= simple_stmt< power< id2=any trailer< '.' 'sort' > trailer< '(' ')' > > '\n' > next=any* > csJtt|ƒj|ƒ}|rFd|krF|d|dkrB|SdS|S)NÚsortedZid1Zid2)Úsuperr Úmatch)ÚselfÚnodeÚr)Ú __class__©ú=/opt/alt/python35/lib64/python3.5/lib2to3/fixes/fix_idioms.pyr Os zFixIdioms.matchcCsdd|kr|j||ƒSd|kr8|j||ƒSd|krT|j||ƒStdƒ‚dS)NÚ isinstanceÚwhiler z Invalid match)Útransform_isinstanceÚtransform_whileÚtransform_sortÚ RuntimeError)r rÚresultsrrrÚ transformZs   zFixIdioms.transformcCs–|djƒ}|djƒ}d|_d|_ttdƒ|tƒ|gƒ}d|kr†d|_ttjtdƒ|gƒ}|j|_|S)NÚxÚTÚú rÚnÚnot)ÚcloneÚprefixrrrrrZnot_test)r rrrrZtestrrrrds  !   zFixIdioms.transform_isinstancecCs*|d}|jtdd|jƒƒdS)NrÚTruer")Úreplacerr")r rrZonerrrrps zFixIdioms.transform_whilec Cs:|d}|d}|jdƒ}|jdƒ}|rW|jtdd|jƒƒnR|r�|jƒ}d|_|jttdƒ|gd|jƒƒn tdƒ‚|jƒ|j}d |kr6|r|jd ƒd |d jf} d j | ƒ|d _n/t ƒ} |j j | ƒ|jd ƒd | _dS) NÚsortÚnextÚlistÚexprr r"rzshould not have reached hereÚ é) Úgetr$rr"r!rrÚremoveÚ rpartitionÚjoinrÚparentZ append_child) r rrZ sort_stmtZ next_stmtZ list_callZ simple_exprÚnewZbtwnZ prefix_linesZend_linerrrrts*          zFixIdioms.transform_sort) Ú__name__Ú __module__Ú __qualname__ZexplicitÚTYPEÚCMPZPATTERNr rrrrrr)rrr %s ' r N)Ú__doc__rrZ fixer_utilrrrrrrr5r4ZBaseFixr rrrrÚs .