o
    w!g*                     @  s   d dl mZ d dlZd dl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 d dlmZ e	r8d dlmZ d	d
 ejD Zh dZdddZG dd dZdS )    )annotationsN)cached_property)GetSetDescriptorType)TYPE_CHECKINGAnyClassVar)
ObjectKind)logger)Sequencec                 C  s   h | ]}| d qS _lstrip).0r    r   ^/mnt/skqttb/ctump_chatbot/chatbot/lib/python3.10/site-packages/_griffe/agents/nodes/runtime.py	<setcomp>       r   >   znumpy.core._multiarray_umathznumpy.core.multiarrayosntr   posixastrbreturnboolc                C  s(   dd |  dD dd | dD kS )Nc                 S  s   g | ]}| d qS r   r   )r   cpnr   r   r   
<listcomp>   r   z$_same_components.<locals>.<listcomp>.)split)r   r   r   r   r   _same_components   s   (r#   c                   @  sj  e Zd ZU dZh dZded< 	 dDdEddZdFddZedFddZ	edGddZ
edHddZedIddZedJddZedKd d!ZedKd"d#ZedKd$d%ZedKd&d'ZedKd(d)ZedKd*d+ZedKd,d-ZedKd.d/ZedKd0d1ZedKd2d3ZedKd4d5ZedKd6d7ZedKd8d9ZedKd:d;ZedLd=d>ZdMd@dAZedHdBdCZdS )N
ObjectNodea)  Helper class to represent an object tree.

    It's not really a tree but more a backward-linked list:
    each node has a reference to its parent, but not to its child (for simplicity purposes and to avoid bugs).

    Each node stores an object, its name, and a reference to its parent node.
    >   __spec__
__loader____builtins__zClassVar[set[str]]exclude_specialsNobjr   namer   parentObjectNode | Noner   Nonec              
   C  s~   zt |}W n ty  } ztd|| W Y d}~nd}~ww t|tr,d}|j}nd}|| _	 || _		 || _
	 || _dS )zInitialize the object.

        Parameters:
            obj: A Python object.
            name: The object's name.
            parent: The object's parent node.
        zCould not unwrap %s: %rNTF)inspectunwrap	Exceptionr	   debug
isinstancer   funcr)   r*   r+   is_cached_property)selfr)   r*   r+   errorr4   r   r   r   __init__)   s$   	
zObjectNode.__init__c                 C  s   d| j dS )NzObjectNode(name=))r*   r5   r   r   r   __repr__K   s   zObjectNode.__repr__c                 C  s$   | j du r| jS | j j d| j S )zThe object's (Python) path.Nr!   )r+   r*   pathr9   r   r   r   r;   N   s   
zObjectNode.pathc                 C  s.   | j r| S | jdur| jjS td| j d)z0The object's module, fetched from the node tree.NzObject node z does not have a parent module)	is_moduler+   module
ValueErrorr;   r9   r   r   r   r=   U   s
   
zObjectNode.module
str | Nonec                 C  s|   z| j jW S  ty=   zt| j p| jj }W n ty#   Y Y dS w z|jjW  Y S  ty<   t	|dd Y  Y S w w )zThe object's module path.N__name__)
r)   
__module__AttributeErrorr.   	getmoduler=   r>   r%   r*   getattr)r5   r=   r   r   r   module_path^   s   
zObjectNode.module_pathr   c                 C  s   | j rtjS | jrtjS | jrtjS | jrtjS | j	rtj
S | jr$tjS | jr*tjS | jr0tjS | jr6tjS | jr<tjS | jrBtjS | jrHtjS | jrNtjS tjS )zThe kind of this node.)r<   r   MODULEis_classCLASSis_staticmethodSTATICMETHODis_classmethodCLASSMETHODr4   CACHED_PROPERTY	is_methodMETHODis_builtin_methodBUILTIN_METHODis_coroutine	COROUTINEis_builtin_functionBUILTIN_FUNCTIONis_method_descriptorMETHOD_DESCRIPTORis_functionFUNCTIONis_getset_descriptorGETSET_DESCRIPTORis_propertyPROPERTY	ATTRIBUTEr9   r   r   r   kindm   s6   zObjectNode.kindSequence[ObjectNode]c                 C  s>   g }t | jD ]\}}| ||r|t||| d q|S )zThe children of this node.)r+   )r.   
getmembersr)   _pick_memberappendr$   )r5   childrenr*   memberr   r   r   rd      s   zObjectNode.childrenr   c                 C     t | jS )z'Whether this node's object is a module.)r.   ismoduler)   r9   r   r   r   r<         zObjectNode.is_modulec                 C  rf   )z&Whether this node's object is a class.)r.   isclassr)   r9   r   r   r   rG      rh   zObjectNode.is_classc                 C  s   t | jpt| jo| j S )z)Whether this node's object is a function.)r.   
isfunctionr)   callablerG   r9   r   r   r   rX      s   zObjectNode.is_functionc                 C  rf   )z1Whether this node's object is a builtin function.)r.   	isbuiltinr)   r9   r   r   r   rT      rh   zObjectNode.is_builtin_functionc                 C  rf   )z*Whether this node's object is a coroutine.)r.   iscoroutinefunctionr)   r9   r   r   r   rR      rh   zObjectNode.is_coroutinec                 C  s   t | jtS )z3Whether this node's object is a get/set descriptor.)r2   r)   r   r9   r   r   r   rZ      rh   zObjectNode.is_getset_descriptorc                 C  s   t | jtp| jS )z)Whether this node's object is a property.)r2   r)   propertyr4   r9   r   r   r   r\         zObjectNode.is_propertyc                 C  s   t | jo| jjS )z4Whether the object of this node's parent is a class.)r   r+   rG   r9   r   r   r   parent_is_class   ro   zObjectNode.parent_is_classc                 C  s   t dd }| jot| j|S )z'Whether this node's object is a method.c                   S  s   d S Nr   r   r   r   r   <lambda>   s    z&ObjectNode.is_method.<locals>.<lambda>)typerp   r2   r)   )r5   function_typer   r   r   rN      s   zObjectNode.is_methodc                 C  rf   )zWhether this node's object is a method descriptor.

        Built-in methods (e.g. those implemented in C/Rust) are often
        method descriptors, rather than normal methods.
        )r.   ismethoddescriptorr)   r9   r   r   r   rV      s   zObjectNode.is_method_descriptorc                 C  s   | j o| jS )z/Whether this node's object is a builtin method.)rT   rp   r9   r   r   r   rP      rh   zObjectNode.is_builtin_methodc                 C  L   | j du rdS z| j jj| jd}W n
 ty   Y dS w | jo%t|tS )z-Whether this node's object is a staticmethod.NF)	r+   r)   __dict__getr*   rB   rp   r2   staticmethodr5   self_from_parentr   r   r   rI         
zObjectNode.is_staticmethodc                 C  rv   )z,Whether this node's object is a classmethod.NF)	r+   r)   rw   rx   r*   rB   rp   r2   classmethodrz   r   r   r   rK      r|   zObjectNode.is_classmethodc                 C  s   | j tju S )z+Whether this node's object is an attribute.)r_   r   r^   r9   r   r   r   is_attribute   rh   zObjectNode.is_attributeset[int]c                 C  s*   | j d u rt| jhS t| jh| j jB S rq   )r+   idr)   _idsr9   r   r   r   r      s   
zObjectNode._idsre   c                 C  s6   || j vo|tuo|tuot|| jvo|t| jv S rq   )r(   rs   objectr   r   varsr)   )r5   r*   re   r   r   r   rb      s   
zObjectNode._pick_memberc                 C  s   | j du rdS | jrdS | j}|sdS | j j}|sdS ||ftv r#dS t||r*dS |dtv r6|d}| jr;|S t| j	d| j
t| jj
d d }| d| S )z?Alias target path of this node, if the node should be an alias.Nr   __qualname__   r!   )r+   r~   rE   _cyclic_relationshipsr#   r   _builtin_module_namesr<   rD   r)   r;   lenr=   )r5   child_module_pathparent_module_path
child_namer   r   r   alias_target_path   s(   


$zObjectNode.alias_target_pathrq   )r)   r   r*   r   r+   r,   r   r-   )r   r   )r   r$   )r   r?   )r   r   )r   r`   )r   r   )r   r   )r*   r   re   r   r   r   ) r@   rA   r   __doc__r(   __annotations__r7   r:   rn   r;   r=   rE   r_   r   rd   r<   rG   rX   rT   rR   rZ   r\   rp   rN   rV   rP   rI   rK   r~   r   rb   r   r   r   r   r   r$      sb   
 
"


	r$   )r   r   r   r   r   r   )
__future__r   r.   sys	functoolsr   typesr   typingr   r   r   _griffe.enumerationsr   _griffe.loggerr	   collections.abcr
   builtin_module_namesr   r   r#   r$   r   r   r   r   <module>   s   
