3 ^@sdZddlmZddlmZddlmZddlmZmZm Z m Z m Z m Z ddZ Gdd d ejZd d Zd d ZgdfddZddZdS)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)AssignNameNewlineNumber SubscriptsymscCst|tjo|jdjtjkS)N) isinstancerNodechildrentyperSTRING)stmtr6/usr/lib64/python3.6/lib2to3/fixes/fix_tuple_params.py is_docstrings rc@s(eZdZdZdZdZddZddZdS) FixTupleParamsTa funcdef< 'def' any parameters< '(' args=any ')' > ['->' any] ':' suite=any+ > | lambda= lambdef< 'lambda' args=vfpdef< '(' inner=any ')' > ':' body=any > c sd|krj||Sg|d}|d}|djdjtjkrZd}|djdj}tnd}d}tjtjddfd d }|jt j kr||n@|jt j krx2t |jD]$\}} | jt j kr|| |dkd qWsdSxD]} |d| _ qW|} |dkrd d_n&t|dj|r8|d_|d} xD]} |d| _ q>W|dj| | <x4t| d| tdD]}||dj|_qW|djdS)Nlambdasuiteargsr rz; Fcs\tj}|j}d|_t||j}|r2d|_|j|jtjt j |jgdS)Nr ) rnew_namecloneprefixrreplaceappendrr r Z simple_stmt)Z tuple_arg add_prefixnargr)end new_linesselfrr handle_tupleCs   z.FixTupleParams.transform..handle_tuple)r"r)F)transform_lambdarrrINDENTvaluerrZLeafr ZtfpdefZ typedargslist enumerateparentrrrangelenZchanged) r'noderesultsrrstartindentr(ir$lineafterr)r%r&r'r transform.sF           zFixTupleParams.transformc Cs|d}|d}t|d}|jtjkrD|j}d|_|j|dSt|}t|}|j t |}t |dd} |j| jxd|j D]X} | jtjkr| j |krdd|| j D} tjtj| jg| } | j| _| j| qWdS)Nrbodyinnerr)rcSsg|] }|jqSr)r).0crrr sz3FixTupleParams.transform_lambda..) simplify_argsrrNAMErrr find_params map_to_indexr tuple_namerZ post_orderr+rr r Zpower) r'r0r1rr8r9ZparamsZto_indexZtup_nameZ new_paramr#Z subscriptsnewrrrr)ns(    zFixTupleParams.transform_lambdaN)__name__ __module__ __qualname__Z run_orderZ BM_compatibleZPATTERNr7r)rrrrrs  @rcCsR|jtjtjfkr|S|jtjkrBx|jtjkr<|jd}q$W|Std|dS)NrzReceived unexpected node %s)rr Zvfplistrr>vfpdefr RuntimeError)r0rrrr=s r=cCs<|jtjkrt|jdS|jtjkr,|jSdd|jDS)NrcSs g|]}|jtjkrt|qSr)rrCOMMAr?)r:r;rrrr<szfind_params..)rr rFr?rrr>r+)r0rrrr?s   r?NcCs^|dkr i}xLt|D]@\}}ttt|g}t|trJt|||dq||||<qW|S)N)d)r,r rstrr listr@) param_listrrIr4objZtrailerrrrr@s r@cCs@g}x0|D](}t|tr(|jt|q |j|q Wdj|S)N_)r rKr!rAjoin)rLlrMrrrrAs   rA)__doc__rrZpgen2rrZ fixer_utilrrrrr r rZBaseFixrr=r?r@rArrrrs    l