o
    i1                     @  s   U d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dlm
Z
mZmZ d dlmZ d dlmZ e
rCd dlZd dlmZ d	ed
< zd dlZW n eyY   efZY nw eef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
ModuleType)TYPE_CHECKINGAnyClassVar)
ObjectKind)logger)Sequenceztuple[types.ModuleType, ...]_TYPING_MODULESc                 C  s   h | ]}| d qS _lstrip).0r    r   k/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/griffe/_internal/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                   @  sx  e Zd ZU dZh dZded< 	 dFdGddZdHddZedHddZ	edIddZ
edJddZedKddZedLddZedMd d!ZedMd"d#ZedMd$d%ZedMd&d'ZedMd(d)ZedMd*d+ZedMd,d-ZedMd.d/ZedMd0d1ZedMd2d3ZedMd4d5ZedMd6d7ZedMd8d9ZedMd:d;ZedMd<d=ZedNd?d@ZdOdBdCZedJdDdEZ dS )P
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-   errorr6   r   r   r   __init__4   s$   	
zObjectNode.__init__c                 C  s   d| j dS )NzObjectNode(name=))r,   r7   r   r   r   __repr__V   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,   pathr;   r   r   r   r=   Y   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=   r;   r   r   r   r?   `   s
   
zObjectNode.module
str | Nonec                 C  s   z| j j}W n8 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 t
|trUtd| j t	|dt	|ddS t
|tr\|S td| jt	t|dtt| dS )zThe object's module path.N__name__zObject %s has its `__module__` attribute set to a module object: it must be a string instead (the module fully qualified name). Please report to the maintainers of this library.__qualname__zObject %s has its `__module__` attribute set to a %s object: it must be a string instead (the module fully qualified name). Please report to the maintainers of this library.)r+   
__module__AttributeErrorr0   	getmoduler?   r@   r'   r,   getattrr4   r   r
   r3   r=   r   type)r7   r?   r   r   r   module_pathi   s8   

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 | jrTtjS tjS )zThe kind of this node.)r>   r	   MODULEis_classCLASSis_staticmethodSTATICMETHODis_classmethodCLASSMETHODr6   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is_type_alias
TYPE_ALIAS	ATTRIBUTEr;   r   r   r   kind   s:   zObjectNode.kindSequence[ObjectNode]c                 C  s>   g }t | jD ]\}}| ||r|t||| d q|S )zThe children of this node.)r-   )r0   
getmembersr+   _pick_memberappendr&   )r7   childrenr,   memberr   r   r   rj      s   zObjectNode.childrenr    c                 C     t | jS )z'Whether this node's object is a module.)r0   ismoduler+   r;   r   r   r   r>         zObjectNode.is_modulec                 C  rl   )z&Whether this node's object is a class.)r0   isclassr+   r;   r   r   r   rK      rn   zObjectNode.is_classc                 C  s   t | jpt| jo| j S )z)Whether this node's object is a function.)r0   
isfunctionr+   callablerK   r;   r   r   r   r\      s   zObjectNode.is_functionc                 C  s   t | jtdd tD S )z+Whether this node's object is a type alias.c                 s  s     | ]}t |d r|jV  qdS )TypeAliasTypeN)hasattrrr   )r   r?   r   r   r   	<genexpr>   s    z+ObjectNode.is_type_alias.<locals>.<genexpr>)r4   r+   tupler   r;   r   r   r   rb      s   zObjectNode.is_type_aliasc                 C  rl   )z1Whether this node's object is a builtin function.)r0   	isbuiltinr+   r;   r   r   r   rX      rn   zObjectNode.is_builtin_functionc                 C  rl   )z*Whether this node's object is a coroutine.)r0   iscoroutinefunctionr+   r;   r   r   r   rV      rn   zObjectNode.is_coroutinec                 C  s   t | jtS )z3Whether this node's object is a get/set descriptor.)r4   r+   r   r;   r   r   r   r^      rn   zObjectNode.is_getset_descriptorc                 C  s   t | jtp| jS )z)Whether this node's object is a property.)r4   r+   propertyr6   r;   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-   rK   r;   r   r   r   parent_is_class   ry   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>)rH   rz   r4   r+   )r7   function_typer   r   r   rR      s   zObjectNode.is_methodc                 C  rl   )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.
        )r0   ismethoddescriptorr+   r;   r   r   r   rZ      s   zObjectNode.is_method_descriptorc                 C  s   | j o| jS )z/Whether this node's object is a builtin method.)rX   rz   r;   r   r   r   rT      rn   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,   rE   rz   r4   staticmethodr7   self_from_parentr   r   r   rM         
zObjectNode.is_staticmethodc                 C  r   )z,Whether this node's object is a classmethod.NF)	r-   r+   r   r   r,   rE   rz   r4   classmethodr   r   r   r   rO     r   zObjectNode.is_classmethodc                 C  s   | j tju S )z+Whether this node's object is an attribute.)re   r	   rd   r;   r   r   r   is_attribute  rn   zObjectNode.is_attributeset[int]c                 C  s*   | j d u rt| jhS t| jh| j jB S r{   )r-   idr+   _idsr;   r   r   r   r     s   
zObjectNode._idsrk   c                 C  s6   || j vo|tuo|tuot|| jvo|t| jv S r{   )r*   rH   objectr   r   varsr+   )r7   r,   rk   r   r   r   rh     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   rC      r#   )r-   r   rI   _cyclic_relationshipsr%   r   _builtin_module_namesr>   rG   r+   r=   lenr?   )r7   child_module_pathparent_module_path
child_namer   r   r   alias_target_path&  s(   


$zObjectNode.alias_target_pathr{   )r+   r   r,   r   r-   r.   r   r/   )r   r   )r   r&   )r   rA   )r   r	   )r   rf   )r   r    )r   r   )r,   r   rk   r   r   r    )!rB   rD   rC   __doc__r*   __annotations__r9   r<   rx   r=   r?   rI   re   r   rj   r>   rK   r\   rb   rX   rV   r^   r`   rz   rR   rZ   rT   rM   rO   r   r   rh   r   r   r   r   r   r&   (   sf   
 
"# 


	r&   )r   r   r   r   r   r    )
__future__r   r0   systyping	functoolsr   typesr   r   r   r   r   griffe._internal.enumerationsr	   griffe._internal.loggerr
   collections.abcr   r   typing_extensionsImportErrorr   builtin_module_namesr   r   r%   r&   r   r   r   r   <module>   s.   

