Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/sys/lib/python2.7/lib2to3/fixes/fix_idioms.pyo

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�`^c@smdZddlmZddlmZmZmZmZmZm	Z	dZ
dZdejfd��YZ
dS(	s�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)
i(t
fixer_base(tCalltCommatNametNodet	BlankLinetsymss0(n='!=' | '==' | 'is' | n=comp_op< 'is' 'not' >)s(power< 'type' trailer< '(' x=any ')' > >t	FixIdiomscBsQeZeZdeeeefZd�Zd�Zd�Z	d�Z
d�ZRS(s�
        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+>) 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*
        >
    cCsJtt|�j|�}|rFd|krF|d|dkrB|SdS|S(Ntsortedtid1tid2(tsuperRtmatchtNone(tselftnodetr((s./sys/lib/python2.7/lib2to3/fixes/fix_idioms.pyROscCsdd|kr|j||�Sd|kr8|j||�Sd|krT|j||�Std��dS(Nt
isinstancetwhileRs
Invalid match(ttransform_isinstancettransform_whilettransform_sorttRuntimeError(RRtresults((s./sys/lib/python2.7/lib2to3/fixes/fix_idioms.pyt	transformZscCs�|dj�}|dj�}d|_d|_ttd�|t�|g�}d|kr�d|_ttjtd�|g�}n|j|_|S(NtxtTuu u
isinstancetnunot(tclonetprefixRRRRRtnot_test(RRRRRttest((s./sys/lib/python2.7/lib2to3/fixes/fix_idioms.pyRds		!	!cCs*|d}|jtdd|j��dS(NRuTrueR(treplaceRR(RRRtone((s./sys/lib/python2.7/lib2to3/fixes/fix_idioms.pyRps
cCs=|d}|d}|jd�}|jd�}|rW|jtdd|j��nR|r�|j�}d|_|jttd�|gd|j��ntd��|j�|j}d	|kr9|r|jd	�d
|d
jf}	d	j	|	�|d
_q9t
�}
|jj|
�|jd	�d
|
_ndS(NtsorttnexttlisttexprusortedRusshould not have reached hereu
i(
tgetR RRRRRtremovet
rpartitiontjoinRtparenttappend_child(RRRt	sort_stmtt	next_stmtt	list_calltsimple_exprtnewtbtwntprefix_linestend_line((s./sys/lib/python2.7/lib2to3/fixes/fix_idioms.pyRts*

	
	 	(t__name__t
__module__tTruetexplicittTYPEtCMPtPATTERNRRRRR(((s./sys/lib/python2.7/lib2to3/fixes/fix_idioms.pyR%s'		
		N(t__doc__tRt
fixer_utilRRRRRRR9R8tBaseFixR(((s./sys/lib/python2.7/lib2to3/fixes/fix_idioms.pyt<module>s
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].