
    gQ                        d dl mZ d dlmZ d dlmZ d dlmZ erd dlm	Z	 ddZ
ddZddZdd	Zdd
ZddZddZddZddZy)    )annotations)AST)TYPE_CHECKING)LastNodeError)Iteratorc                J    | j                   j                  j                         S )zvReturn the kind of an AST node.

    Parameters:
        node: The AST node.

    Returns:
        The node kind.
    )	__class____name__lowernodes    M/var/www/openai/venv/lib/python3.12/site-packages/_griffe/agents/nodes/ast.pyast_kindr      s     >>""((**    c              #    K   | j                   D ]_  }	 t        | |      }t        |t              r| |_        | ,t        |t              s=|D ]  }t        |t              s| |_        |   a y# t        $ r Y nw xY ww)z}Return the children of an AST node.

    Parameters:
        node: The AST node.

    Yields:
        The node children.
    N)_fieldsgetattrAttributeError
isinstancer   parentlist)r   
field_namefieldchilds       r   ast_childrenr      s|      ll
	D*-E eS!ELKt$eS)#'ELK  #  		s3   BA2,BB"B2	A>;B=A>>Bc              #  T   K   t        | j                        D ]  }|| ur|  y yw)zReturn the previous siblings of this node, starting from the closest.

    Parameters:
        node: The AST node.

    Yields:
        The previous siblings.
    Nr   r   )r   siblings     r   ast_previous_siblingsr   2   s+       ,$M	 -s   &(c              #  h   K   t        | j                        }|D ]  }|| u s n |E d{    y7 w)zReturn the next siblings of this node, starting from the closest.

    Parameters:
        node: The AST node.

    Yields:
        The next siblings.
    Nr   r   siblingsr   s      r   ast_next_siblingsr#   B   s5      DKK(Hd?  s   2202c              #  p   K   t        | j                        }|D ]  }|| ur|  n |E d{    y7 w)zvReturn the siblings of this node.

    Parameters:
        node: The AST node.

    Yields:
        The siblings.
    Nr   r!   s      r   ast_siblingsr%   R   s;      DKK(H$M	 
 s   ,646c                V    	 t        |       ^ }}|S # t        $ r t        d      dw xY w)zReturn the previous sibling of this node.

    Parameters:
        node: The AST node.

    Raises:
        LastNodeError: When the node does not have previous siblings.

    Returns:
        The sibling.
    zthere is no previous nodeN)r   
ValueErrorr   )r   _lasts      r   ast_previousr*   d   s>    C(.D K  C78dBCs    (c                ^    	 t        t        |             S # t        $ r t        d      dw xY w)zReturn the next sibling of this node.

    Parameters:
        node: The AST node.

    Raises:
        LastNodeError: When the node does not have next siblings.

    Returns:
        The sibling.
    zthere is no next nodeN)nextr#   StopIterationr   r   s    r   ast_nextr.   w   s5    ?%d+,, ?34$>?s    ,c                f    	 t        t        |             S # t        $ r}t        d      |d}~ww xY w)zReturn the first child of this node.

    Parameters:
        node: The AST node.

    Raises:
        LastNodeError: When the node does not have children.

    Returns:
        The child.
    there are no children nodeN)r,   r   r-   r   )r   errors     r   ast_first_childr2      s8    EL&'' E89uDEs    	0+0c                ^    	 t        |       ^ }}|S # t        $ r}t        d      |d}~ww xY w)zReturn the lasts child of this node.

    Parameters:
        node: The AST node.

    Raises:
        LastNodeError: When the node does not have children.

    Returns:
        The child.
    r0   N)r   r'   r   )r   r(   r)   r1   s       r   ast_last_childr4      s?    E%D K  E89uDEs    	,',N)r   r   returnstr)r   r   r5   zIterator[AST])r   r   r5   r   )
__future__r   astr   typingr   _griffe.exceptionsr   collections.abcr   r   r   r   r#   r%   r*   r.   r2   r4    r   r   <module>r=      sG    #    ,(	+ 0  $&?$E$r   