ok
Direktori : /lib64/python3.6/lib2to3/fixes/__pycache__/ |
Current File : //lib64/python3.6/lib2to3/fixes/__pycache__/fix_idioms.cpython-36.opt-1.pyc |
3 \ � @ sN d Z ddlmZ ddlmZmZmZmZmZm Z dZ dZG dd� 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 ')' > >c sP e Zd ZdZdeeeef Z� fdd�Zdd� Zdd� Z d d � Z dd� Z� ZS ) � 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+>) 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* > c s8 t t| �j|�}|r4d|kr4|d |d kr0|S d S |S )N�sortedZid1Zid2)�superr �match)�self�node�r)� __class__� �0/usr/lib64/python3.6/lib2to3/fixes/fix_idioms.pyr O s zFixIdioms.matchc C sH d|kr| j ||�S d|kr(| j||�S d|kr<| j||�S td��d S )N� isinstance�whiler z Invalid match)�transform_isinstance�transform_while�transform_sort�RuntimeError)r r �resultsr r r � transformZ s zFixIdioms.transformc C sh |d j � }|d j � }d|_d|_ttd�|t� |g�}d|kr\d|_ttjtd�|g�}|j|_|S )N�x�T� � r �n�not)�clone�prefixr r r r r Znot_test)r r r r r Ztestr r r r d s zFixIdioms.transform_isinstancec C s |d }|j td|jd�� d S )Nr �True)r"