3 ^c@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) isinstancerNodechildrentyperZSTRING)stmtr6/usr/lib64/python3.6/lib2to3/fixes/fix_tuple_params.py is_docstrings rc@s(eZdZdZdZdZddZddZdS) FixTupleParamsiTa 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)NZlambdasuiteargsr rz; Fcs\tj}|j}d|_t||j}|r2d|_|j|jtjt j |jgdS)Nr ) rnew_namecloneprefixrreplaceappendrr r Z simple_stmt)Z tuple_arg add_prefixnargrZendZ new_linesselfrr handle_tupleCs   z.FixTupleParams.transform..handle_tuple)rr)F)transform_lambdar rrZINDENTvaluerrZLeafr ZtfpdefZ typedargslist enumerateZparentrrZrangeZlenZchanged) r"noderesultsrrZstartZindentr#ir ZlineZafterrr!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)rZ.0Zcrrr z3FixTupleParams.transform_lambda..) simplify_argsrrNAMErrr find_params map_to_indexr tuple_namerZ post_orderr%rr r Zpower) r"r'r(rr+r,ZparamsZto_indexZtup_nameZ new_paramrZ subscriptsZnewrrrr$ns(    zFixTupleParams.transform_lambdaN)Z__name__Z __module__Z __qualname__Z run_orderZ BM_compatibleZPATTERNr*r$rrrrrs  @rcCsR|jtjtjfkr|S|jtjkrBx|jtjkr<|jd}q$W|Std|dS)NrzReceived unexpected node %s)rr Zvfplistrr1vfpdefr Z RuntimeErrorr'rrrr0s r0cCs<|jtjkrt|jdS|jtjkr,|jSdd|jDS)NrcSs g|]}|jtjkrt|qSr)rrZCOMMAr2r-rrrr.r/zfind_params..)rr r5r2r rr1r%r6rrrr2s   r2NcCs^|dkr i}xLt|D]@\}}ttt|g}t|trJt|||dq||||<qW|S)N)d)r&rrZstrr listr3) param_listrr7r)objZtrailerrrrr3s r3cCs@g}x0|D](}t|tr(|jt|q |j|q Wdj|S)NZ_)r r8rr4Zjoin)r9Zlr:rrrr4s   r4)Z__doc__rrZpgen2rrZ fixer_utilrrrrrr rZBaseFixrr0r2r3r4rrrrZs    l