
    g'                        d dl mZ d dlZd dl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rd dlmZ ej                   D  ch c]  } | j#                  d       c} Zh d	Zdd
Z G d d      Zyc c} w )    )annotationsN)cached_property)TYPE_CHECKINGAnyClassVar)
ObjectKind)logger)Sequence_>   znumpy.core._multiarray_umathznumpy.core.multiarrayosntr   posixc                   | j                  d      D cg c]  }|j                  d       c}|j                  d      D cg c]  }|j                  d       c}k(  S c c}w c c}w )N.r   )splitlstrip)abcpns      Q/var/www/openai/venv/lib/python3.12/site-packages/_griffe/agents/nodes/runtime.py_same_componentsr      sX    '(wws|4|CJJsO|4TUT[T[\_T`8aT`SCT`8aaa48as   AA#c                     e Zd ZU dZh dZded<   	 dddZddZedd       Z	edd	       Z
ed d
       Zed!d       Zed"d       Zed#d       Zed#d       Zed#d       Zed#d       Zed#d       Zed#d       Zed#d       Zed#d       Zed#d       Zed#d       Zed#d       Zed#d       Zed$d       Zd%dZed d       Zy)&
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_specialsNc                
   	 t        j                  |      }t        |t              rd}|j                  }nd}|| _        	 || _	        	 || _
        	 || _        y# t        $ r!}t        j                  d||       Y d}~fd}~ww xY w)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   funcobjnameparentis_cached_property)selfr(   r)   r*   errorr+   s         r   __init__zObjectNode.__init__(   s    	A..%C c?+!%((C!&'	')/(:>+  	A
 LL2D%@@	As   A 	B!A==Bc                "    d| j                   dS )NzObjectNode(name=))r)   r,   s    r   __repr__zObjectNode.__repr__J   s    !$))a00    c                |    | j                   | j                  S | j                   j                   d| j                   S )zThe object's (Python) path.r   )r*   r)   pathr1   s    r   r5   zObjectNode.pathM   s8     ;;99++""#1TYYK00r3   c                    | j                   r| S | j                  | j                  j                  S t        d| j                   d      )z0The object's module, fetched from the node tree.zObject node z does not have a parent module)	is_moduler*   module
ValueErrorr5   r1   s    r   r8   zObjectNode.moduleT   sC     >>K;;";;%%%<		{2PQRRr3   c                J   	 | j                   j                  S # t        $ r 	 t        j                  | j                         xs | j
                  j                   }n# t        $ r Y Y yw xY w	 |j                  j                  cY S # t        $ r t        |dd      cY cY S w xY ww xY w)zThe object's module path.N__name__)
r(   
__module__AttributeErrorr"   	getmoduler8   r9   r   r)   getattr)r,   r8   s     r   module_pathzObjectNode.module_path]   s    
	988&&& 	9 **4884G 9+++! 9vz4889	9sP    	B"7AB"	A'#B"&A''B"+B B"BB"BB"c                   | 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                  rt        j                   S | j"                  rt        j$                  S | j&                  rt        j(                  S | j*                  rt        j,                  S | j.                  rt        j0                  S t        j2                  S )zThe kind of this node.)r7   r   MODULEis_classCLASSis_staticmethodSTATICMETHODis_classmethodCLASSMETHODr+   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_propertyPROPERTY	ATTRIBUTEr1   s    r   kindzObjectNode.kindl   s    >>$$$==###***)))""--->>$$$!!,,,'''##...$$///&&&&&&###r3   c                    g }t        j                  | j                        D ]5  \  }}| j                  ||      s|j	                  t        |||              7 |S )zThe children of this node.)r*   )r"   
getmembersr(   _pick_memberappendr   )r,   childrenr)   members       r   r^   zObjectNode.children   sR     #..txx8LD&  v.
64 EF 9 r3   c                @    t        j                  | j                        S )z'Whether this node's object is a module.)r"   ismoduler(   r1   s    r   r7   zObjectNode.is_module   s     ))r3   c                @    t        j                  | j                        S )z&Whether this node's object is a class.)r"   isclassr(   r1   s    r   rC   zObjectNode.is_class   s     txx((r3   c                    t        j                  | j                        xs$ t        | j                        xr | j                   S )z)Whether this node's object is a function.)r"   
isfunctionr(   callablerC   r1   s    r   rT   zObjectNode.is_function   s3     !!$((+Y0B0X4==GXYr3   c                @    t        j                  | j                        S )z1Whether this node's object is a builtin function.)r"   	isbuiltinr(   r1   s    r   rP   zObjectNode.is_builtin_function   s       **r3   c                @    t        j                  | j                        S )z*Whether this node's object is a coroutine.)r"   iscoroutinefunctionr(   r1   s    r   rN   zObjectNode.is_coroutine   s     **48844r3   c                R    t        | j                  t              xs | j                  S )z)Whether this node's object is a property.)r&   r(   propertyr+   r1   s    r   rV   zObjectNode.is_property   s      $((H-H1H1HHr3   c                \    t        | j                  xr | j                  j                        S )z4Whether the object of this node's parent is a class.)boolr*   rC   r1   s    r   parent_is_classzObjectNode.parent_is_class   s"     DKK8DKK$8$899r3   c                b    t        d       }| j                  xr t        | j                  |      S )z'Whether this node's object is a method.c                      y N rs   r3   r   <lambda>z&ObjectNode.is_method.<locals>.<lambda>   s    Tr3   )typero   r&   r(   )r,   function_types     r   rJ   zObjectNode.is_method   s*     \*##K
488](KKr3   c                @    t        j                  | j                        S )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(   r1   s    r   rR   zObjectNode.is_method_descriptor   s     ))$((33r3   c                6    | j                   xr | j                  S )z/Whether this node's object is a builtin method.)rP   ro   r1   s    r   rL   zObjectNode.is_builtin_method   s     ''@D,@,@@r3   c                    | j                   y	 | j                   j                  j                  j                  | j                  d      }| j                  xr t        |t              S # t
        $ r Y yw xY w)z-Whether this node's object is a staticmethod.NF)	r*   r(   __dict__getr)   r=   ro   r&   staticmethodr,   self_from_parents     r   rE   zObjectNode.is_staticmethod   sj     ;;	#{{77;;DIItL ##R
3C\(RR  		   :A' '	A32A3c                    | j                   y	 | j                   j                  j                  j                  | j                  d      }| j                  xr t        |t              S # t
        $ r Y yw xY w)z,Whether this node's object is a classmethod.NF)	r*   r(   r{   r|   r)   r=   ro   r&   classmethodr~   s     r   rG   zObjectNode.is_classmethod   sj     ;;	#{{77;;DIItL ##Q
3C[(QQ  		r   c                    | j                   t        | j                        hS t        | j                        h| j                   j                  z  S rr   )r*   idr(   _idsr1   s    r   r   zObjectNode._ids   s;    ;;txxL>!488~ 0 000r3   c                    || j                   vxrD |t        uxr: |t        uxr0 t        |      | j                  vxr |t        | j                        v S rr   )r    ru   objectr   r   varsr(   )r,   r)   r_   s      r   r\   zObjectNode._pick_member   s]    --- 'd"'f$' 6
$))+' TXX&	
r3   c                   | j                   y| j                  }|sy| j                   j                  }|sy||ft        v ryt        ||      ry|j	                  d      t
        v r|j	                  d      }| j                  r|S t        | j                  d| j                  t        | j                  j                        dz   d       }| d| S )z?Alias target path of this node, if the node should be an alias.Nr   __qualname__   r   )r*   r@   _cyclic_relationshipsr   r   _builtin_module_namesr7   r?   r(   r5   lenr8   )r,   child_module_pathparent_module_path
child_names       r   alias_target_pathzObjectNode.alias_target_path   s     ;; !,,  "[[44!  126KK .0AB ##C(,AA 1 8 8 =>>$$TXX~tyyT[[EUEUAVYZAZA\7]^
#$Aj\22r3   rr   )r(   r   r)   strr*   zObjectNode | NonereturnNone)r   r   )r   r   )r   z
str | None)r   r   )r   zSequence[ObjectNode])r   rn   )r   zset[int])r)   r   r_   r   r   rn   )r;   r<   r   __doc__r    __annotations__r.   r2   rl   r5   r8   r@   rY   r   r^   r7   rC   rT   rP   rN   rV   ro   rJ   rR   rL   rE   rG   r   r\   r   rs   r3   r   r   r      s    ,V(UL ?D1 1 1 S S 9 9 $ $8   * * ) ) Z Z
 + + 5 5 I I : : L L
 4 4 A A S S R R 1 1

 %3 %3r3   r   )r   r   r   r   r   rn   )
__future__r   r"   sys	functoolsr   typingr   r   r   _griffe.enumerationsr   _griffe.loggerr	   collections.abcr
   builtin_module_namesr   r   r   r   r   )r   s   0r   <module>r      sj    #  
 % / / + !(030H0HI0H1#0HI  by3 y3 Js   A/