o
    DDi4                     @   sj   d dl mZmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
mZmZ d dlmZ G dd de
eZd	S )
    )ABCabstractmethod)contextmanager)replace)	Generator)MetadataDependentMetadataWrapperModule)CodemodContextc                   @   s   e Zd ZdZdeddfddZdefddZd	eddfd
dZ	e
defddZededefddZededeeddf fddZdedefddZdS )Codemoda  
    Abstract base class that all codemods must subclass from. Classes wishing
    to perform arbitrary, non-visitor-based mutations on a tree should subclass
    from this class directly. Classes wishing to perform visitor-based mutation
    should instead subclass from :class:`~libcst.codemod.ContextAwareTransformer`.

    Note that a :class:`~libcst.codemod.Codemod` is a subclass of
    :class:`~libcst.MetadataDependent`, meaning that you can declare metadata
    dependencies with the :attr:`~libcst.MetadataDependent.METADATA_DEPENDENCIES`
    class property and while you are executing a transform you can call
    :meth:`~libcst.MetadataDependent.get_metadata` to retrieve
    the resolved metadata.
    contextreturnNc                 C   s   t |  || _d S )N)r   __init__r   )selfr    r   P/var/www/Datamplify/venv/lib/python3.10/site-packages/libcst/codemod/_codemod.pyr      s   

zCodemod.__init__c                 C      dS )z
        Override this and return ``True`` to allow your transform to be called
        repeatedly until the tree doesn't change between passes. By default,
        this is off, and should suffice for most transforms.
        Fr   )r   r   r   r   should_allow_multiple_passes"   s   z$Codemod.should_allow_multiple_passeswarningc                 C   s   | j j| dS )z\
        Emit a warning that is displayed to the user who has invoked this codemod.
        N)r   warningsappend)r   r   r   r   r   warn*   s   zCodemod.warnc                 C   s,   | j j}|du rtd| jj dd |S )av  
        Reference to the currently-traversed module. Note that this is only available
        during the execution of a codemod. The module reference is particularly
        handy if you want to use :meth:`libcst.Module.code_for_node` or
        :attr:`libcst.Module.config_for_parsing` and don't wish to track a reference
        to the top-level module manually.
        NzAttempted access of z.module outside of ztransform_module().)r   module	Exception	__class____name__)r   r   r   r   r   r   0   s   	zCodemod.moduletreec                 C   r   )z
        Override this with your transform. You should take in the tree, optionally
        mutate it and then return the mutated version. The module reference and all
        calculated metadata are available for the lifetime of this function.
        Nr   )r   r   r   r   r   transform_module_implA   s   zCodemod.transform_module_implr   c                 c   s    | j j}| j j}| j j}|d ur|r||}t||d}nt|}| |) t| j |d| _ z|jV  W t| j |d| _ n	t| j |d| _ w W d    d S 1 sTw   Y  d S )N)cache)wrapper)	r   r   metadata_managerfilenameget_cache_for_pathr   resolver   r   )r   r   
oldwrapperr    r!   r   r   r   r   r   _handle_metadata_referenceJ   s   

&"z"Codemod._handle_metadata_referencec                 C   s   |   s| |}| |W  d   S 1 sw   Y  |}	 | |}| |}W d   n1 s6w   Y  ||rC	 |S |}q!)a   
        Transform entrypoint which handles multi-pass logic and metadata calculation
        for you. This is the method that you should call if you wish to invoke a
        codemod directly. This is the method that is called by
        :func:`~libcst.codemod.transform_module`.
        N)r   r%   r   deep_equals)r   r   tree_with_metadatapreviousr   r   r   transform_moduleb   s    
zCodemod.transform_module)r   
__module____qualname____doc__r
   r   boolr   strr   propertyr	   r   r   r   r   r   r%   r)   r   r   r   r   r      s     r   N)abcr   r   
contextlibr   dataclassesr   typingr   libcstr   r   r	   libcst.codemod._contextr
   r   r   r   r   r   <module>   s   