o
     wiN                     @   sd   d dl mZmZmZ d dlZd dlmZ d dlmZ d dl	m
Z
mZ d dlmZ G dd deZdS )    )DictSequenceUnionN)CSTLogicError)CodemodContextVisitorBasedCodemodCommand)insert_header_commentsc                       s   e Zd ZU dZdZeed< ddgZee ed< de	dd	f fd
dZ
dejdd	fddZdejdd	fddZdejdejdeejejf fddZdejdejdejfddZ  ZS )FixPyreDirectivesCommandz
    Given a source file, we'll move the any strict or unsafe tag to the top of the
    file if it contains one. Also tries to fix typo'd directives.
    z<Fixes common misspelling and location errors with pyre tags.DESCRIPTIONstrictunsafe	PYRE_TAGScontextreturnNc                    s:   t  | dd | jD | _dd | jD | _d| _d S )Nc                 S      i | ]}|d qS )F .0tagr   r   h/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/libcst/codemod/commands/fix_pyre_directives.py
<dictcomp>       z5FixPyreDirectivesCommand.__init__.<locals>.<dictcomp>c                 S   r   )r   r   r   r   r   r   r      r   F)super__init__r   move_strictmodule_header_tagsin_module_header)selfr   	__class__r   r   r      s   
z!FixPyreDirectivesCommand.__init__nodec                 C   s   | j rtdd| _ d S )NLogic error!Tr   r   r   r    r   r   r   visit_Module_header      
z,FixPyreDirectivesCommand.visit_Module_headerc                 C   s   | j stdd| _ d S )Nr!   Fr"   r#   r   r   r   leave_Module_header$   r%   z,FixPyreDirectivesCommand.leave_Module_headeroriginal_nodeupdated_nodec              	   C   s   | j D ]}t|tjtd| drD| jr2| j|  d7  < | j| dkr.t   S |  S | j| dk r>d| j	|< t   S t|tjtd| dr| jr{| j|  d7  < | j| dkrmt   S |j
td| d  S | j| dk rd| j	|< t   S q|S )N# pyre-)comment   Tz# pyre )r   mmatches	EmptyLineCommentr   r   libcstRemoveFromParentr   with_changes)r   r'   r(   r   r   r   r   leave_EmptyLine)   s.   
 
 

z(FixPyreDirectivesCommand.leave_EmptyLinec                    s    fdd j D }t||S )Nc                    s    g | ]} j | rd | qS )r)   )r   r   r   r   r   
<listcomp>X   s     z9FixPyreDirectivesCommand.leave_Module.<locals>.<listcomp>)r   r   )r   r'   r(   commentsr   r4   r   leave_ModuleU   s   
z%FixPyreDirectivesCommand.leave_Module)__name__
__module____qualname____doc__r
   str__annotations__r   r   r   r   r0   Moduler$   r&   r.   r   RemovalSentinelr3   r7   __classcell__r   r   r   r   r	      s*   
 
,r	   )typingr   r   r   r0   libcst.matchersmatchersr,   r   libcst.codemodr   r   libcst.helpersr   r	   r   r   r   r   <module>   s   