grthtrhthjhtyjytjytkergtrhtrjytjerhrfh3 \ ã@sNdZddlmZddlmZmZmZmZmZm 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 ')' > >csPeZdZdZdeeeefZ‡fdd„Zdd„Zdd„Z d d „Z d d „Z ‡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* > cs8tt|ƒj|ƒ}|r4d|kr4|d|dkr0|SdS|S)NÚsortedZid1Zid2)Úsuperr Úmatch)ÚselfÚnodeÚr)Ú __class__©ú0/usr/lib64/python3.6/lib2to3/fixes/fix_idioms.pyr Os  zFixIdioms.matchcCsHd|kr|j||ƒSd|kr(|j||ƒSd|kr<|j||ƒStdƒ‚dS)NÚ isinstanceÚwhiler z Invalid match)Útransform_isinstanceÚtransform_whileÚtransform_sortÚ RuntimeError)r rÚresultsrrrÚ transformZs   zFixIdioms.transformcCsh|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}|jtd|jd�ƒdS)NrÚTrue)r")Úreplacerr")r rrZonerrrrpszFixIdioms.transform_whilec Csà|d}|d}|jdƒ}|jdƒ}|r>|jtd|jd�ƒn8|rn|jƒ}d|_|jttdƒ|g|jd�ƒntdƒ‚|jƒ|j}d |krÜ|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 rrrrÚ __classcell__rr)rrr %s'   r N)Ú__doc__rrZ fixer_utilrrrrrrr5r4ZBaseFixr rrrrÚs