o
    hU]                     @  s  U d dl mZ d dl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 d dlmZ d dlmZmZmZ d dlmZmZ d d	lmZ d d
lmZ erd dlZd dlmZ d dlmZ d dlmZ d dl m!Z! d dl"m#Z# d dl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ G dd de,Z-G dd de-dZ.ee/e0e/ef e.e,e. f Z1	 G dd dZ2dhZ3de4d< 	 d*dd Z5d+d$d%Z6d,d(d)Z7dS )-    )annotationsN)suppress)module_from_specspec_from_file_location)isclass)Path)TYPE_CHECKINGAnyUnion)ast_childrenast_kind)ExtensionNotLoadedError)dynamic_import)
ModuleType)	Inspector)
ObjectNode)Visitor)GriffeLoader)Alias	AttributeClassFunctionModuleObject	TypeAliasc                      s"   e Zd ZdZd fd	d
Z  ZS )_ExtensionMetaclassz Metaclass for Griffe extensions.namestrbasestuple[type, ...]attrsdict[str, Any]returnc                   s   d|v rt jdtdd d|v r,t|d j}d|v s d|v r,d|d	< t jd
tdd d|v r8t jdtdd t | |||S )Non_package_loadedzHThe `on_package_loaded` event is deprecated and renamed to `on_package`.   )
stacklevelon_aliasnodeagentT__old_on_aliaszThe `on_alias` event is now a load event and receives the `alias` and `loader` parameters. It doesn't receive the `node` or `agent` parameters anymore. Please use the new `on_alias` signature, or rename your hook to `on_alias_instance`.   on_wildcard_expansionzThe `on_wildcard_expansion` event is deprecated. Instead, hook onto the `on_alias` event and check for aliases' `wildcard_imported` boolean attribute.)warningswarnDeprecationWarninginspect	signature
parameterssuper__new__)clsr   r   r    r1   	__class__ a/var/www/html/openai_agents/venv/lib/python3.10/site-packages/griffe/_internal/extensions/base.pyr3   #   s,   z_ExtensionMetaclass.__new__)r   r   r   r   r    r!   r"   r   )__name__
__module____qualname____doc__r3   __classcell__r7   r7   r5   r8   r       s    r   c                   @  s(  e Zd ZdZdVddZdVdd	ZdWddZdWddZdXddZdYddZ	dZddZ
dYddZdXd d!Zd[d$d%Zd\d&d'Zd[d(d)ZdXd*d+Zd]d.d/Zd^d0d1Zd]d2d3ZdXd4d5Zd_d8d9Zd`d:d;ZdXd<d=Zdad@dAZdbdBdCZdXdDdEZdcdHdIZdddJdKZdedNdOZdfdPdQZdgdSdTZdUS )h	Extensionz!Base class for Griffe extensions.r'   ast.ASTr"   Nonec                 C  s"   t | dt| dd | dS )zPVisit a node.

        Parameters:
            node: The node to visit.
        visit_c                 S     d S Nr7   _r7   r7   r8   <lambda>I       z!Extension.visit.<locals>.<lambda>N)getattrr   selfr'   r7   r7   r8   visitC   s   "zExtension.visitc                 C  s   t |D ]}| | qdS )zhVisit children nodes.

        Parameters:
            node: The node to visit the children of.
        N)r   rK   rJ   r'   childr7   r7   r8   generic_visitK   s   zExtension.generic_visitr   c                 C  s    t | d|j dd | dS )zTInspect a node.

        Parameters:
            node: The node to inspect.
        inspect_c                 S  rB   rC   r7   rD   r7   r7   r8   rF   Z   rG   z#Extension.inspect.<locals>.<lambda>N)rH   kindrI   r7   r7   r8   r/   T   s    zExtension.inspectc                 C  s    |j D ]
}|js| | qdS )zxExtend the base generic inspection with extensions.

        Parameters:
            node: The node to inspect.
        N)childrenalias_target_pathr/   rL   r7   r7   r8   generic_inspect\   s
   

zExtension.generic_inspectast.AST | ObjectNoder(   Visitor | Inspectorkwargsr	   c                K     dS )zRun when visiting a new node during static/dynamic analysis.

        Parameters:
            node: The currently visited node.
        Nr7   rJ   r'   r(   rV   r7   r7   r8   on_nodef   rG   zExtension.on_nodeobjr   c                K  rW   )a  Run when an Object has been created.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            obj: The object instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr7   rJ   r'   rZ   r(   rV   r7   r7   r8   on_instancem   rG   zExtension.on_instanceloaderr   c                K  rW   )a  Run on objects (every kind) once the object tree has been fully constructed.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            obj: The object instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr7   )rJ   rZ   r]   rV   r7   r7   r8   	on_object   rG   zExtension.on_objectc                K  rW   )a  Run when members of an Object have been loaded.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            obj: The object instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr7   r[   r7   r7   r8   
on_members   rG   zExtension.on_membersc                K  rW   )zRun when visiting a new module node during static/dynamic analysis.

        Parameters:
            node: The currently visited node.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr7   rX   r7   r7   r8   on_module_node   rG   zExtension.on_module_nodemodr   c                K  rW   )a  Run when a Module has been created.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            mod: The module instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr7   rJ   r'   ra   r(   rV   r7   r7   r8   on_module_instance   rG   zExtension.on_module_instancec                K  rW   )a  Run on modules once the object tree has been fully constructed.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            mod: The module instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr7   )rJ   ra   r]   rV   r7   r7   r8   	on_module   rG   zExtension.on_modulec                K  rW   )a  Run when members of a Module have been loaded.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            mod: The module instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr7   rb   r7   r7   r8   on_module_members   rG   zExtension.on_module_membersc                K  rW   )zRun when visiting a new class node during static/dynamic analysis.

        Parameters:
            node: The currently visited node.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr7   rX   r7   r7   r8   on_class_node   rG   zExtension.on_class_noder4   r   c                K  rW   )a  Run when a Class has been created.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            cls: The class instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr7   rJ   r'   r4   r(   rV   r7   r7   r8   on_class_instance   rG   zExtension.on_class_instancec                K  rW   )a  Run on classes once the object tree has been fully constructed.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            cls: The class instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr7   )rJ   r4   r]   rV   r7   r7   r8   on_class   rG   zExtension.on_classc                K  rW   )a   Run when members of a Class have been loaded.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            cls: The class instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr7   rg   r7   r7   r8   on_class_members  rG   zExtension.on_class_membersc                K  rW   )zRun when visiting a new function node during static/dynamic analysis.

        Parameters:
            node: The currently visited node.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr7   rX   r7   r7   r8   on_function_node#  rG   zExtension.on_function_nodefuncr   c                K  rW   )a  Run when a Function has been created.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            func: The function instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr7   )rJ   r'   rl   r(   rV   r7   r7   r8   on_function_instance,  rG   zExtension.on_function_instancec                K  rW   )a  Run on functions once the object tree has been fully constructed.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            func: The function instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr7   )rJ   rl   r]   rV   r7   r7   r8   on_functionB  rG   zExtension.on_functionc                K  rW   )zRun when visiting a new attribute node during static/dynamic analysis.

        Parameters:
            node: The currently visited node.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr7   rX   r7   r7   r8   on_attribute_nodeO  rG   zExtension.on_attribute_nodeattrr   c                K  rW   )a  Run when an Attribute has been created.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            attr: The attribute instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr7   )rJ   r'   rp   r(   rV   r7   r7   r8   on_attribute_instanceX  rG   zExtension.on_attribute_instancec                K  rW   )a  Run on attributes once the object tree has been fully constructed.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            attr: The attribute instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr7   )rJ   rp   r]   rV   r7   r7   r8   on_attributen  rG   zExtension.on_attributec                K  rW   )zRun when visiting a new type alias node during static/dynamic analysis.

        Parameters:
            node: The currently visited node.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr7   rX   r7   r7   r8   on_type_alias_node{  rG   zExtension.on_type_alias_node
type_aliasr   c                K  rW   )a  Run when a TypeAlias has been created.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            type_alias: The type alias instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr7   )rJ   r'   rt   r(   rV   r7   r7   r8   on_type_alias_instance  rG   z Extension.on_type_alias_instancec                K  rW   )a  Run on type aliases once the object tree has been fully constructed.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            type_alias: The type alias instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr7   )rJ   rt   r]   rV   r7   r7   r8   on_type_alias  rG   zExtension.on_type_aliasaliasr   c                K  s,   t | ddr| jd|||d| dS dS )a  Run when an Alias has been created.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            alias: The alias instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        r)   F)r'   rw   r(   Nr7   )rH   r&   )rJ   r'   rw   r(   rV   r7   r7   r8   on_alias_instance  s   zExtension.on_alias_instancec                K  rW   )a  Run on aliases once the object tree has been fully constructed.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            alias: The alias instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr7   )rJ   rw   r]   rV   r7   r7   r8   r&     rG   zExtension.on_aliaspkgc                K  s(   t | dr| jd||d| dS dS )a  Run when a package has been completely loaded.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            pkg: The package (Module) instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        r#   )ry   r]   Nr7   )hasattrr#   )rJ   ry   r]   rV   r7   r7   r8   
on_package  s   
zExtension.on_packageN)r'   r?   r"   r@   )r'   r   r"   r@   )r'   rT   r(   rU   rV   r	   r"   r@   )
r'   rT   rZ   r   r(   rU   rV   r	   r"   r@   )rZ   r   r]   r   rV   r	   r"   r@   )
r'   rT   ra   r   r(   rU   rV   r	   r"   r@   )ra   r   r]   r   rV   r	   r"   r@   )
r'   rT   r4   r   r(   rU   rV   r	   r"   r@   )r4   r   r]   r   rV   r	   r"   r@   )
r'   rT   rl   r   r(   rU   rV   r	   r"   r@   )rl   r   r]   r   rV   r	   r"   r@   )
r'   rT   rp   r   r(   rU   rV   r	   r"   r@   )rp   r   r]   r   rV   r	   r"   r@   )
r'   rT   rt   r   r(   rU   rV   r	   r"   r@   )rt   r   r]   r   rV   r	   r"   r@   )
r'   rT   rw   r   r(   rU   rV   r	   r"   r@   )rw   r   r]   r   rV   r	   r"   r@   )ry   r   r]   r   rV   r	   r"   r@   ) r9   r:   r;   r<   rK   rN   r/   rS   rY   r\   r^   r_   r`   rc   rd   re   rf   rh   ri   rj   rk   rm   rn   ro   rq   rr   rs   ru   rv   rx   r&   r{   r7   r7   r7   r8   r>   @   s<    


	







	



	



	


	


	


r>   )	metaclassc                   @  s8   e Zd ZdZdddZddd	ZdddZdddZdS )
ExtensionszLThis class helps iterating on extensions that should run at different times.
extensionsr>   r"   r@   c                 G  s   g | _ | j|  dS )zrInitialize the extensions container.

        Parameters:
            *extensions: The extensions to add.
        N)_extensionsadd)rJ   r~   r7   r7   r8   __init__  s   zExtensions.__init__c                 G  s   |D ]}| j | qdS )zoAdd extensions to this container.

        Parameters:
            *extensions: The extensions to add.
        N)r   append)rJ   r~   	extensionr7   r7   r8   r     s   zExtensions.addrV   r	   c                 K  rW   )z!No-op method for extension hooks.Nr7   )rJ   rV   r7   r7   r8   _noop  rG   zExtensions._noopeventr   c              	   K  sz   | j D ]7}|dkr.t|ddr.tt t||di | W d   n1 s(w   Y  qt||| jdi | qdS )zCall the extension hook for the given event.

        Parameters:
            event: The triggered event.
            **kwargs: Arguments passed to the hook.
        r&   r)   FNr7   )r   rH   r   	TypeErrorr   )rJ   r   rV   r   r7   r7   r8   call  s   

zExtensions.callN)r~   r>   r"   r@   )rV   r	   r"   r@   )r   r   rV   r	   r"   r@   )r9   r:   r;   r<   r   r   r   r   r7   r7   r7   r8   r}     s    

	
	r}   dataclasseszset[str]builtin_extensionspathr   r"   r   c                 C  sX   t j| ddd }t|| }|std|  dt|}|tj|< |j	
| |S )N.r*   r   z#Could not import module from path '')osr   basenamersplitr   r   r   sysmodulesr]   exec_module)r   module_namespecmoduler7   r7   r8   _load_extension_path  s   

r   r   2str | dict[str, Any] | Extension | type[Extension]Extension | list[Extension]c              
     s  d}t | tr	| S t| rt| tr|  S t | tr)tt|  \} t|}nt| }i  |	d}|dksA|rJdt
|jvrJ|dd\}}nd}|tv rVd| }n"tj|rxzt|}W n tyw } z	td| d|d}~ww |szt|}W n+ ty } z	td| d|d}~w ty } ztd| d| |d}~ww t|rt|tr|di  S |rzt||di  W S  ty } ztd| d	| d
|d}~ww dd t| D } fdd|D S )a  Load a configured extension.

    Parameters:
        extension: An extension, with potential configuration options.

    Raises:
        ExtensionNotLoadedError: When the extension cannot be loaded,
            either because the module is not found, or because it does not expose
            the Extension attribute. ImportError will bubble up so users can see
            the traceback.

    Returns:
        An extension instance.
    N:r*   zgriffe._internal.extensions.zExtension module 'z' could not be foundz!Error while importing extension 'z': z
' has no 'z' attributec                 S  s*   g | ]}t |rt|tr|tur|qS r7   )r   
issubclassr>   ).0rZ   r7   r7   r8   
<listcomp>o  s    z#_load_extension.<locals>.<listcomp>c                   s   g | ]	}|d i  qS )r7   r7   )r   extoptionsr7   r8   r   r  s    r7   )
isinstancer>   r   r   dictnextiteritemsr   countr   driver   r   r   r   existsr   ImportErrorr   r   ModuleNotFoundErrorrH   AttributeErrorvarsvalues)r   
ext_objectimport_pathcolonsextension_nameerrorr~   r7   r   r8   _load_extension  sd   




r   extsLoadableExtensionTypec                  G  st   t  }| D ]}t|}t|tr|j|  q|| qddlm} |jD ]}t||u r0 |S q%|jtd  |S )zLoad configured extensions.

    Parameters:
        exts: Extensions with potential configuration options.

    Returns:
        An extensions container.
    r   )DataclassesExtensionr   )	r}   r   r   listr   'griffe._internal.extensions.dataclassesr   r   type)r   r~   r   r   r   r7   r7   r8   load_extensionsu  s   	

r   )r   r   r"   r   )r   r   r"   r   )r   r   r"   r}   )8
__future__r   r/   r   r   r,   
contextlibr   importlib.utilr   r   r   pathlibr   typingr   r	   r
   !griffe._internal.agents.nodes.astr   r   griffe._internal.exceptionsr   griffe._internal.importerr   asttypesr   !griffe._internal.agents.inspectorr   %griffe._internal.agents.nodes.runtimer   griffe._internal.agents.visitorr   griffe._internal.loaderr   griffe._internal.modelsr   r   r   r   r   r   r   r   r   r>   r   r   r   r}   r   __annotations__r   r   r   r7   r7   r7   r8   <module>   sF   $     )

[