o
    DDi"                     @   s   d dl Z d dlmZmZmZmZmZmZmZm	Z	 d dl
mZ d dlmZ d dlmZmZ e	r4d dlmZ edgdf Zeeee f ZG dd	 d	eeZ		dd
edee dee dee def
ddZdee defddZG dd deZdS )    N)CallablecastIterableListMappingMutableMappingOptionalTYPE_CHECKING)MetadataDependent)CSTTypedVisitorFunctions)CSTNodeT
CSTVisitor)CSTNoder   c                   @   s&   e Zd ZdZdeeef fddZdS )BatchableCSTVisitoraq  
    The low-level base visitor class for traversing a CST as part of a batched
    set of traversals. This should be used in conjunction with the
    :func:`~libcst.visit_batched` function or the
    :func:`~libcst.MetadataWrapper.visit_batched` method from
    :class:`~libcst.MetadataWrapper` to visit a tree.
    Instances of this class cannot modify the tree.
    returnc                 C   s   t | dd }t|S )a  
        Returns a mapping of all the ``visit_<Type[CSTNode]>``,
        ``visit_<Type[CSTNode]>_<attribute>``, ``leave_<Type[CSTNode]>`` and
        `leave_<Type[CSTNode]>_<attribute>`` methods defined by this visitor,
        excluding all empty stubs.
        c                 S   s0   t | o| jdp| jdot| dd S )Nvisit_leave_	_is_no_opF)inspectismethod__name__
startswithgetattr)m r   P/var/www/Datamplify/venv/lib/python3.10/site-packages/libcst/_batched_visitor.py<lambda>1   s   
z2BatchableCSTVisitor.get_visitors.<locals>.<lambda>)r   
getmembersdict)selfmethodsr   r   r   get_visitors'   s
   z BatchableCSTVisitor.get_visitorsN)r   
__module____qualname____doc__r   strVisitorMethodr!   r   r   r   r   r      s    	r   nodebatchable_visitorsbefore_visitafter_leaver   c                 C   s&   t |}t|||d}tt| |S )a3  
    Do a batched traversal over ``node`` with all ``visitors``.

    ``before_visit`` and ``after_leave`` are provided as optional hooks to
    execute before the ``visit_<Type[CSTNode]>`` and after the
    ``leave_<Type[CSTNode]>`` methods from each visitor in ``visitor`` are
    executed by the batched visitor.

    This function does not handle metadata dependency resolution for ``visitors``.
    See :func:`~libcst.MetadataWrapper.visit_batched` from
    :class:`~libcst.MetadataWrapper` for batched traversal with metadata dependency
    resolution.
    r)   r*   )_get_visitor_methods_BatchedCSTVisitorr   r   visit)r'   r(   r)   r*   visitor_methodsbatched_visitorr   r   r   visit_batched?   s
   r1   c                 C   s:   i }| D ]}|   D ]\}}||g | qq|S )z
    Gather all ``visit_<Type[CSTNode]>``, ``visit_<Type[CSTNode]>_<attribute>``,
    ``leave_<Type[CSTNode]>`` amd `leave_<Type[CSTNode]>_<attribute>`` methods
    from ``batchabled_visitors``.
    )r!   items
setdefaultappend)r(   r/   bvnamefnr   r   r   r,   Y   s   r,   c                	       s   e Zd ZU dZeed< ee ed< ee ed< ddddedee dee ddf fdd	Zd
dde	fddZ
dddZd
ddeddfddZdddeddfddZ  ZS )r-   zJ
    Internal visitor class to perform batched traversal over a tree.
    r/   r)   r*   Nr+   r   c                   s    t    || _|| _|| _d S )N)super__init__r/   r)   r*   )r   r/   r)   r*   	__class__r   r   r9   q   s   

z_BatchedCSTVisitor.__init__r'   r   c                 C   sF   | j }|dur|| t|j}| jd| g D ]}|| qdS )zR
        Call appropriate visit methods on node before visiting children.
        Nr   T)r)   typer   r/   get)r   r'   r)   	type_namevr   r   r   on_visit}   s   

z_BatchedCSTVisitor.on_visitoriginal_nodec                 C   sJ   t |j}| jd| g D ]}|| q| j}|dur#|| dS dS )zQ
        Call appropriate leave methods on node after visiting children.
        r   N)r<   r   r/   r=   r*   )r   rA   r>   r?   r*   r   r   r   on_leave   s   

z_BatchedCSTVisitor.on_leave	attributec                 C   6   t |j}| jd| d| g D ]}|| qdS )zp
        Call appropriate visit attribute methods on node before visiting
        attribute's children.
        r   _Nr<   r   r/   r=   )r   r'   rC   r>   r?   r   r   r   on_visit_attribute      

z%_BatchedCSTVisitor.on_visit_attributec                 C   rD   )zo
        Call appropriate leave attribute methods on node after visiting
        attribute's children.
        r   rE   NrF   )r   rA   rC   r>   r?   r   r   r   on_leave_attribute   rH   z%_BatchedCSTVisitor.on_leave_attribute)rA   r   r   N)r   r"   r#   r$   _VisitorMethodCollection__annotations__r   r&   r9   boolr@   rB   r%   rG   rI   __classcell__r   r   r:   r   r-   h   s(   
 
	r-   )NN)r   typingr   r   r   r   r   r   r   r	   libcst._metadata_dependentr
   libcst._typed_visitorr   libcst._visitorsr   r   libcst._nodes.baser   r&   r%   rJ   r   r1   r,   r-   r   r   r   r   <module>   s:   (%

