grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a ´i ã@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|ƒ |¡}|r4d|vr4|d|dkr0|SdS|S)NÚsortedZid1Zid2)Úsuperr Úmatch)ÚselfÚnodeÚr©Ú __class__©ú0/usr/lib64/python3.9/lib2to3/fixes/fix_idioms.pyr Os  zFixIdioms.matchcCsHd|vr| ||¡Sd|vr(| ||¡Sd|vr<| ||¡Stdƒ‚dS)NÚ isinstanceÚwhiler z Invalid match)Útransform_isinstanceÚtransform_whileÚtransform_sortÚ RuntimeError)r rÚresultsrrrÚ transformZs   zFixIdioms.transformcCsh|d ¡}|d ¡}d|_d|_ttdƒ|tƒ|gƒ}d|vr\d|_ttjtdƒ|gƒ}|j|_|S)NÚxÚTÚú rÚnÚnot)ÚcloneÚprefixrrrrrZnot_test)r rrrrÚtestrrrrds  zFixIdioms.transform_isinstancecCs |d}| td|jd�¡dS)NrÚTrue©r#)Úreplacerr#)r rrZonerrrrpszFixIdioms.transform_whilec Csà|d}|d}| d¡}| d¡}|r>| td|jd�¡n8|rn| ¡}d|_| ttdƒ|g|jd�¡ntdƒ‚| ¡|j}d |vrÜ|rº| d ¡d |d jf} d   | ¡|d _n"t ƒ} |j   | ¡| d ¡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__rrrrr %s% Û'   r N)Ú__doc__rrZ fixer_utilrrrrrrr8r7ZBaseFixr rrrrÚs