o
    DDi                     @   s|   U d dl Z d dlZd dlmZmZ d dlZd dlmZm	Z	 dddddddZ
eeeeef f ed< G d	d
 d
e	ZdS )    N)DictOptional)CodemodContextVisitorBasedCodemodCommand      )parameter_countargument_count)blackyapfpresets_per_formatterc                       s   e Zd ZU edZeed< 			ddedede	e
 de	e
 d	df
 fd
dZedejd	dfddZdejdejd	ejfddZdejdejd	ejfddZ  ZS )AddTrailingCommasaA  
        Codemod that adds trailing commas to arguments in function
        headers and function calls.

        The idea is that both the black and yapf autoformatters will
        tend to split headers and function calls so that there
        is one parameter / argument per line if there is a trailing
        comma:
        - Black will always separate them by line
        - Yapf appears to do so whenever there are at least two arguments

        Applying this codemod (and then an autoformatter) may make
        it easier to read function definitions and calls
        DESCRIPTIONr
   Ncontext	formatterr   r	   returnc                    s\   t  | t|}|d u rtd|ddt  |p#|d | _|p*|d | _d S )NzUnknown formatter z. Presets exist for z, r   r	   )	super__init__r   get
ValueErrorjoinkeysr   r	   )selfr   r   r   r	   presets	__class__ d/var/www/Datamplify/venv/lib/python3.10/site-packages/libcst/codemod/commands/add_trailing_commas.pyr   ,   s   

zAddTrailingCommas.__init__
arg_parserc                 C   sF   | j ddddtdd | j ddd	d
td d | j ddddtd d d S )Nz--formatterr   	FORMATTERz(Formatter to target (e.g. yapf or black)r
   )destmetavarhelptypedefaultz--paramter-countr   PARAMETER_COUNTz9Minimal number of parameters for us to add trailing commaz--argument-countr	   ARGUMENT_COUNTz8Minimal number of arguments for us to add trailing comma)add_argumentstrint)r   r   r   r   add_args=   s0   
zAddTrailingCommas.add_argsoriginal_nodeupdated_nodec                 C   sx   | j d u pt|j| j k pt|jdko|jd jjdv }|r!|S |jd }|jg |jd d |jt dR dS )Nr   r   >   clsr   comma)params)r   lenr1   namevaluewith_changescstComma)r   r+   r,   skip
last_paramr   r   r   leave_ParametersX   s    
	
z"AddTrailingCommas.leave_Parametersc                 C   sJ   t |j| jk r
|S |jd }|jg |jd d |jt dR dS )Nr.   r/   )args)r2   r;   r	   r5   r6   r7   )r   r+   r,   last_argr   r   r   
leave_Callq   s   
zAddTrailingCommas.leave_Call)r
   NN)__name__
__module____qualname__textwrapdedentr   r(   __annotations__r   r   r)   r   staticmethodargparseArgumentParserr*   r6   
Parametersr:   Callr=   __classcell__r   r   r   r   r      sD   
 
r   )rE   rA   typingr   r   libcstr6   libcst.codemodr   r   r   r(   r)   rC   r   r   r   r   r   <module>   s   
