
    -h*                        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	rd dlmZ d	 ej        D             Zh d
ZddZ G d d          ZdS )    )annotationsN)cached_property)GetSetDescriptorType)TYPE_CHECKINGAnyClassVar)
ObjectKind)logger)Sequencec                8    h | ]}|                     d           S _lstrip).0r   s     Y/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/_griffe/agents/nodes/runtime.py	<setcomp>r      s"    III1#III    >   znumpy.core._multiarray_umathznumpy.core.multiarrayosntr   posixastrbreturnboolc                   d |                      d          D             d |                     d          D             k    S )Nc                8    g | ]}|                     d           S r   r   r   cpns     r   
<listcomp>z$_same_components.<locals>.<listcomp>   s"    444CJJsOO444r   .c                8    g | ]}|                     d           S r   r   r"   s     r   r$   z$_same_components.<locals>.<listcomp>   s"    8a8a8aSC8a8a8ar   )split)r   r   s     r   _same_componentsr(      sD    44qwws||4448a8aTUT[T[\_T`T`8a8a8aaar   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d0d            Zed1d            Zed2d            Zed3d            Zed3d            Zed3d            Zed3d            Zed3d            Zed3d            Zed3d            Zed3d             Zed3d!            Zed3d"            Zed3d#            Zed3d$            Zed3d%            Zed3d&            Zed4d(            Zd5d*Zed0d+            ZdS )6
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                   	 t          j        |          }n-# t          $ r }t          j        d||           Y d}~nd}~ww xY 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/   r0   r1   is_cached_property)selfr/   r0   r1   errorr;   s         r   __init__zObjectNode.__init__)   s    	A.%%CC 	A 	A 	A
 L2D%@@@@@@@@	A c?++ 	'!%(CC!&'	')/(:>>s    
A<Ac                    d| j         dS )NzObjectNode(name=))r0   r<   s    r   __repr__zObjectNode.__repr__K   s    0$)0000r   c                J    | j         | j        S | j         j         d| j         S )zThe object's (Python) path.Nr%   )r1   r0   pathrA   s    r   rD   zObjectNode.pathN   s/     ;9+"00TY000r   c                j    | j         r| S | j        | 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_moduler1   module
ValueErrorrD   rA   s    r   rG   zObjectNode.moduleU   sB     > 	K;";%%Q	QQQRRRr   
str | Nonec                   	 | j         j        S # t          $ rl 	 t          j        | j                   p| j        j         }n# t          $ r Y Y dS 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__AttributeErrorr5   	getmodulerG   rH   r+   r0   getattr)r<   rG   s     r   module_pathzObjectNode.module_path^   s    
	98&& 	9 	9 	9 *4844G   ttt9++++! 9 9 9vz488888889	9sM    
B%?B
A	BABA B B ;B?B  Br	   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          j        S | j        rt          j        S t          j        S )zThe kind of this node.)rF   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_getset_descriptorGETSET_DESCRIPTORis_propertyPROPERTY	ATTRIBUTErA   s    r   kindzObjectNode.kindm   s    > 	%$$= 	$## 	+** 	*))" 	.--> 	%$$! 	-,, 	(''# 	/..$ 	0// 	'&&$ 	0// 	'&&##r   Sequence[ObjectNode]c                    g }t          j        | j                  D ]@\  }}|                     ||          r%|                    t          |||                      A|S )zThe children of this node.)r1   )r5   
getmembersr/   _pick_memberappendr*   )r<   childrenr0   members       r   rq   zObjectNode.children   sk     #.tx88 	G 	GLD&  v.. G
64 E E EFFFr   r   c                4    t          j        | j                  S )z'Whether this node's object is a module.)r5   ismoduler/   rA   s    r   rF   zObjectNode.is_module   s     )))r   c                4    t          j        | j                  S )z&Whether this node's object is a class.)r5   isclassr/   rA   s    r   rS   zObjectNode.is_class   s     tx(((r   c                l    t          j        | j                  pt          | j                  o| j         S )z)Whether this node's object is a function.)r5   
isfunctionr/   callablerS   rA   s    r   rd   zObjectNode.is_function   s0     !$(++Y0B0B0X4=GXYr   c                4    t          j        | j                  S )z1Whether this node's object is a builtin function.)r5   	isbuiltinr/   rA   s    r   r`   zObjectNode.is_builtin_function   s      ***r   c                4    t          j        | j                  S )z*Whether this node's object is a coroutine.)r5   iscoroutinefunctionr/   rA   s    r   r^   zObjectNode.is_coroutine   s     *48444r   c                6    t          | j        t                    S )z3Whether this node's object is a get/set descriptor.)r9   r/   r   rA   s    r   rf   zObjectNode.is_getset_descriptor   s     $($8999r   c                D    t          | j        t                    p| j        S )z)Whether this node's object is a property.)r9   r/   propertyr;   rA   s    r   rh   zObjectNode.is_property   s     $(H--H1HHr   c                B    t          | j        o| j        j                  S )z4Whether the object of this node's parent is a class.)r   r1   rS   rA   s    r   parent_is_classzObjectNode.parent_is_class   s     DK8DK$8999r   c                Z    t          d           }| j        ot          | j        |          S )z'Whether this node's object is a method.c                     d S N r   r   r   <lambda>z&ObjectNode.is_method.<locals>.<lambda>   s    T r   )typer   r9   r/   )r<   function_types     r   rZ   zObjectNode.is_method   s-     \\**#K
48](K(KKr   c                4    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.
        )r5   ismethoddescriptorr/   rA   s    r   rb   zObjectNode.is_method_descriptor   s     )$(333r   c                    | j         o| j        S )z/Whether this node's object is a builtin method.)r`   r   rA   s    r   r\   zObjectNode.is_builtin_method   s     '@D,@@r   c                    | j         dS 	 | j         j        j                            | j        d          }n# t
          $ r Y dS w xY w| j        ot          |t                    S )z-Whether this node's object is a staticmethod.NF)	r1   r/   __dict__getr0   rM   r   r9   staticmethodr<   self_from_parents     r   rU   zObjectNode.is_staticmethod   ss     ;5	#{7;;DItLL 	 	 	55	#R
3C\(R(RR   *6 
AAc                    | j         dS 	 | j         j        j                            | j        d          }n# t
          $ r Y dS w xY w| j        ot          |t                    S )z,Whether this node's object is a classmethod.NF)	r1   r/   r   r   r0   rM   r   r9   classmethodr   s     r   rW   zObjectNode.is_classmethod   ss     ;5	#{7;;DItLL 	 	 	55	#Q
3C[(Q(QQr   c                (    | j         t          j        u S )z+Whether this node's object is an attribute.)rk   r	   rj   rA   s    r   is_attributezObjectNode.is_attribute   s     yJ000r   set[int]c                ~    | j         t          | j                  hS t          | j                  h| j         j        z  S r   )r1   idr/   _idsrA   s    r   r   zObjectNode._ids   s4    ;txLL>!48~ 000r   rr   c                    || j         vo=|t          uo4|t          uo+t          |          | j        vo|t          | j                  v S r   )r.   r   objectr   r   varsr/   )r<   r0   rr   s      r   ro   zObjectNode._pick_member   sZ    -- 'd"'f$' 6

$)+' TX&	
r   c                   | j         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 r|                    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%   )r1   r   rP   _cyclic_relationshipsr(   r   _builtin_module_namesrF   rO   r/   rD   lenrG   )r<   child_module_pathparent_module_path
child_names       r   alias_target_pathzObjectNode.alias_target_path   s    ;4  	4 !,  	4 "[4! 	4  126KKK4 .0ABB 	4 ##C((,AAA 1 8 8 = = > 	%$$ TX~tyT[EUAVAVYZAZA\A\7]^^
#22j222r   r   )r/   r   r0   r   r1   r2   r   r3   )r   r   )r   r*   )r   rI   )r   r	   )r   rl   )r   r   )r   r   )r0   r   rr   r   r   r   ) rK   rL   r   __doc__r.   __annotations__r>   rB   r   rD   rG   rP   rk   r   rq   rF   rS   rd   r`   r^   rf   rh   r   rZ   rb   r\   rU   rW   r   r   ro   r   r   r   r   r*   r*      s<          ,V+U+UUUUUL ?  ?  ?  ?  ?D1 1 1 1 1 1 1 X1 S S S XS 9 9 9 X9 $ $ $ X$<    _ * * * _* ) ) ) _) Z Z Z _Z
 + + + _+ 5 5 5 _5 : : : _: I I I _I : : : _: L L L _L
 4 4 4 _4 A A A _A S S S _S R R R _R 1 1 1 _1 1 1 1 _1

 
 
 
 .3 .3 .3 _.3 .3 .3r   r*   )r   r   r   r   r   r   )
__future__r   r5   sys	functoolsr   typesr   typingr   r   r   _griffe.enumerationsr	   _griffe.loggerr
   collections.abcr   builtin_module_namesr   r   r(   r*   r   r   r   <module>r      s(   # " " " " "  



 % % % % % % & & & & & & / / / / / / / / / / + + + + + + ! ! ! ! ! ! )((((((II0HIII    b b b bN3 N3 N3 N3 N3 N3 N3 N3 N3 N3r   