AlkantarClanX12

Your IP : 3.138.135.4


Current Path : /opt/alt/python37/lib64/python3.7/lib2to3/fixes/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/lib2to3/fixes/__pycache__/fix_tuple_params.cpython-37.pyc

B

� f��@s�dZddlmZddlmZddlmZddlmZmZm	Z	m
Z
mZmZdd�Z
Gdd	�d	ej�Zd
d�Zdd
�Zgdfdd�Zdd�ZdS)a:Fixer for function definitions with tuple parameters.

def func(((a, b), c), d):
    ...

    ->

def func(x, d):
    ((a, b), c) = x
    ...

It will also support lambdas:

    lambda (x, y): x + y -> lambda t: t[0] + t[1]

    # The parens are a syntax error in Python 3
    lambda (x): x + y -> lambda x: x + y
�)�pytree)�token)�
fixer_base)�Assign�Name�Newline�Number�	Subscript�symscCst|tj�o|jdjtjkS)N�)�
isinstancer�Node�children�typer�STRING)�stmt�r�C/opt/alt/python37/lib64/python3.7/lib2to3/fixes/fix_tuple_params.py�is_docstringsrc@s(eZdZdZdZdZdd�Zdd�ZdS)	�FixTupleParams�Ta
              funcdef< 'def' any parameters< '(' args=any ')' >
                       ['->' any] ':' suite=any+ >
              |
              lambda=
              lambdef< 'lambda' args=vfpdef< '(' inner=any ')' >
                       ':' body=any
              >
              cs�d|kr��||�Sg�|d}|d}|djdjtjkrZd}|djdj}t��nd}d}t�tjd��d���fd
d�	}|jt	j
kr�||�n@|jt	jkr�x2t|j�D]$\}}	|	jt	j
kr�||	|dkd�q�W�s�dSx�D]}
|d|
_
q�W|}|dk�rd
�d_n&t|dj|��r8|�d_|d}x�D]}
|d|
_
�q>W�|dj||�<x4t|d|t��d�D]}||dj|_�q�W|d��dS)N�lambda�suite�argsr�rz; �Fcs\t����}|��}d|_t||���}|r2d|_|�|���t�t	j
|���g��dS)Nr� )r�new_name�clone�prefixr�replace�appendrr
r
Zsimple_stmt)Z	tuple_arg�
add_prefix�n�argr)�end�	new_lines�selfrr�handle_tupleCs
z.FixTupleParams.transform.<locals>.handle_tuple)r"r)F)�transform_lambdarrr�INDENT�valuerrZLeafr
ZtfpdefZ
typedargslist�	enumerate�parentrr�range�lenZchanged)r'�node�resultsrr�start�indentr(�ir$�lineZafterr)r%r&r'r�	transform.sF




 zFixTupleParams.transformc
Cs�|d}|d}t|d�}|jtjkrD|��}d|_|�|�dSt|�}t|�}|�	t
|��}t|dd�}	|�|	���xd|��D]X}
|
jtjkr�|
j
|kr�dd�||
j
D�}t�tj|	��g|�}|
j|_|
�|�q�WdS)Nr�body�innerr)rcSsg|]}|���qSr)r)�.0�crrr�
<listcomp>�sz3FixTupleParams.transform_lambda.<locals>.<listcomp>)�
simplify_argsrr�NAMErrr �find_params�map_to_indexr�
tuple_namerZ
post_orderr+rr
r
Zpower)
r'r0r1rr7r8ZparamsZto_indexZtup_nameZ	new_paramr#Z
subscripts�newrrrr)ns(
zFixTupleParams.transform_lambdaN)�__name__�
__module__�__qualname__Z	run_orderZ
BM_compatibleZPATTERNr6r)rrrrrs

@rcCsR|jtjtjfkr|S|jtjkrBx|jtjkr<|jd}q$W|Std|��dS)NrzReceived unexpected node %s)rr
Zvfplistrr=�vfpdefr�RuntimeError)r0rrrr<�sr<cCs<|jtjkrt|jd�S|jtjkr,|jSdd�|jD�S)NrcSs g|]}|jtjkrt|��qSr)rr�COMMAr>)r9r:rrrr;�szfind_params.<locals>.<listcomp>)rr
rEr>rrr=r+)r0rrrr>�s
r>NcCs^|dkri}xLt|�D]@\}}ttt|���g}t|t�rJt|||d�q||||<qW|S)N)�d)r,r	r�strr�listr?)�
param_listrrHr4�objZtrailerrrrr?�s
r?cCs@g}x0|D](}t|t�r(|�t|��q
|�|�q
Wd�|�S)N�_)rrJr!r@�join)rK�lrLrrrr@�s

r@)�__doc__rrZpgen2rrZ
fixer_utilrrrrr	r
rZBaseFixrr<r>r?r@rrrr�<module>s l