o
    hD                     @  s   d dl m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mZmZ d dlmZ erJd dlmZ d d	lmZmZmZmZmZmZmZ ed
ZdddZG dd dZG dd dZG dd dZG dd dZ G dd deeee Z!dS )    )annotationsN)suppress)TYPE_CHECKINGAnyTypeVar)Kind)AliasResolutionErrorBuiltinModuleErrorCyclicAliasError)merge_stubs)Sequence)Alias	AttributeClassFunctionModuleObject	TypeAlias_ObjTypekeystr | Sequence[str]returnSequence[str]c                 C  s:   t | tr| std| d}nt| }|std|S )NzEmpty strings are not supported.zEmpty tuples are not supported)
isinstancestr
ValueErrorsplitlist)r   parts r    X/var/www/html/openai_agents/venv/lib/python3.10/site-packages/griffe/_internal/mixins.py
_get_parts   s   
r"   c                   @  $   e Zd ZdZdddZddd	Zd
S )GetMembersMixinz3Mixin class to share methods for accessing members.r   r   r   r   c                 C  s<   t |}t|dkr| j|d  S | j|d  |dd  S )a  Get a member with its name or path.

        This method is part of the consumer API:
        do not use when producing Griffe trees!

        Members will be looked up in both declared members and inherited ones,
        triggering computation of the latter.

        Parameters:
            key: The name or path of the member.

        Examples:
            >>> foo = griffe_object["foo"]
            >>> bar = griffe_object["path.to.bar"]
            >>> qux = griffe_object[("path", "to", "qux")]
           r   N)r"   lenall_membersselfr   r   r    r    r!   __getitem__%   s   zGetMembersMixin.__getitem__c                 C  s>   t |}t|dkr| j|d  S | j|d  |dd S )a  Get a member with its name or path.

        This method is part of the producer API:
        you can use it safely while building Griffe trees
        (for example in Griffe extensions).

        Members will be looked up in declared members only, not inherited ones.

        Parameters:
            key: The name or path of the member.

        Examples:
            >>> foo = griffe_object["foo"]
            >>> bar = griffe_object["path.to.bar"]
            >>> bar = griffe_object[("path", "to", "bar")]
        r%   r   N)r"   r&   members
get_memberr(   r    r    r!   r,   ;   s   zGetMembersMixin.get_memberN)r   r   r   r   )__name__
__module____qualname____doc__r*   r,   r    r    r    r!   r$   "   s    
r$   c                   @  r#   )DelMembersMixinz2Mixin class to share methods for deleting members.r   r   r   Nonec                 C  sd   t |}t|dkr$|d }z| j|= W dS  ty#   | j|= Y dS w | j|d  |dd = dS )a  Delete a member with its name or path.

        This method is part of the consumer API:
        do not use when producing Griffe trees!

        Members will be looked up in both declared members and inherited ones,
        triggering computation of the latter.

        Parameters:
            key: The name or path of the member.

        Examples:
            >>> del griffe_object["foo"]
            >>> del griffe_object["path.to.bar"]
            >>> del griffe_object[("path", "to", "qux")]
        r%   r   N)r"   r&   r+   KeyErrorinherited_membersr'   r)   r   r   namer    r    r!   __delitem__W   s   zDelMembersMixin.__delitem__c                 C  sH   t |}t|dkr|d }| j|= dS | j|d  |dd  dS )a  Delete a member with its name or path.

        This method is part of the producer API:
        you can use it safely while building Griffe trees
        (for example in Griffe extensions).

        Members will be looked up in declared members only, not inherited ones.

        Parameters:
            key: The name or path of the member.

        Examples:
            >>> griffe_object.del_member("foo")
            >>> griffe_object.del_member("path.to.bar")
            >>> griffe_object.del_member(("path", "to", "qux"))
        r%   r   N)r"   r&   r+   
del_memberr5   r    r    r!   r8   r   s
    zDelMembersMixin.del_memberN)r   r   r   r2   )r-   r.   r/   r0   r7   r8   r    r    r    r!   r1   T   s    
r1   c                   @  s$   e Zd ZdZddd	Zdd
dZdS )SetMembersMixinz1Mixin class to share methods for setting members.r   r   valueObject | Aliasr   r2   c                 C  s^   t |}t|dkr |d }|| j|< | jr| |_dS | |_dS || j|d  |dd < dS )a  Set a member with its name or path.

        This method is part of the consumer API:
        do not use when producing Griffe trees!

        Parameters:
            key: The name or path of the member.
            value: The member.

        Examples:
            >>> griffe_object["foo"] = foo
            >>> griffe_object["path.to.bar"] = bar
            >>> griffe_object[("path", "to", "qux")] = qux
        r%   r   N)r"   r&   r+   is_collection_modules_collectionparent)r)   r   r:   r   r6   r    r    r!   __setitem__   s   


zSetMembersMixin.__setitem__c              	   C  s<  t |}t|dkr|d }|| jv r{| j| }|js{|jr\|js\|js\ttt	t
* |jrM|j|jkrMtt t||}W d   n1 sHw   Y  W d   n1 sWw   Y  |j D ]}tt	 ||_W d   n1 suw   Y  qa|| j|< | jr| |_dS | |_dS | j|d  |dd | dS )a  Set a member with its name or path.

        This method is part of the producer API:
        you can use it safely while building Griffe trees
        (for example in Griffe extensions).

        Parameters:
            key: The name or path of the member.
            value: The member.

        Examples:
            >>> griffe_object.set_member("foo", foo)
            >>> griffe_object.set_member("path.to.bar", bar)
            >>> griffe_object.set_member(("path", "to", "qux"), qux)
        r%   r   N)r"   r&   r+   is_alias	is_moduleis_namespace_packageis_namespace_subpackager   r   r
   r	   filepathr   r   aliasesvaluestargetr<   r=   r>   
set_member)r)   r   r:   r   r6   memberaliasr    r    r!   rH      s0   






"zSetMembersMixin.set_memberN)r   r   r:   r;   r   r2   )r-   r.   r/   r0   r?   rH   r    r    r    r!   r9      s    
r9   c                   @  s.   e Zd ZdZdddd
dZedddZdS )SerializationMixinz8Mixin class to share methods for de/serializing objects.F)fullrL   boolkwargsr   r   r   c                K  s$   ddl m} tj| f||d|S )a  Return this object's data as a JSON string.

        Parameters:
            full: Whether to return full info, or just base info.
            **kwargs: Additional serialization options passed to encoder.

        Returns:
            A JSON string.
        r   )JSONEncoder)clsrL   )griffe._internal.encodersrO   jsondumps)r)   rL   rN   rO   r    r    r!   as_json   s   
zSerializationMixin.as_jsonrP   type[_ObjType]json_stringr   c                 K  sF   ddl m} |d| tj|fi |}t|| s!td|  |S )a  Create an instance of this class from a JSON string.

        Parameters:
            json_string: JSON to decode into Object.
            **kwargs: Additional options passed to decoder.

        Returns:
            An Object instance.

        Raises:
            TypeError: When the json_string does not represent and object
                of the class from which this classmethod has been called.
        r   )json_decoderobject_hookz$provided JSON object is not of type )rQ   rW   
setdefaultrR   loadsr   	TypeError)rP   rV   rN   rW   objr    r    r!   	from_json   s   
zSerializationMixin.from_jsonN)rL   rM   rN   r   r   r   )rP   rU   rV   r   rN   r   r   r   )r-   r.   r/   r0   rT   classmethodr]   r    r    r    r!   rK      s
    rK   c                   @  s   e Zd ZdZed)ddZed*ddZed+d
dZed,ddZed-ddZ	ed.ddZ
ed/ddZed/ddZed/ddZed/ddZed/ddZed/d d!Zed/d"d#Zed/d$d%Zed/d&d'Zd(S )0ObjectAliasMixinzPMixin class to share methods that appear both in objects and aliases, unchanged.r   dict[str, Object | Alias]c                 C  s   | j ri | j| jS | jS )zAll members (declared and inherited).

        This method is part of the consumer API:
        do not use when producing Griffe trees!
        )is_classr4   r+   r)   r    r    r!   r'      s   zObjectAliasMixin.all_membersdict[str, Module]c                 C     dd | j  D S )z~The module members.

        This method is part of the consumer API:
        do not use when producing Griffe trees!
        c                 S  "   i | ]\}}|j tju r||qS r    )kindr   MODULE.0r6   rI   r    r    r!   
<dictcomp>     " z,ObjectAliasMixin.modules.<locals>.<dictcomp>r'   itemsrb   r    r    r!   modules     zObjectAliasMixin.modulesdict[str, Class]c                 C  rd   )z}The class members.

        This method is part of the consumer API:
        do not use when producing Griffe trees!
        c                 S  re   r    )rf   r   CLASSrh   r    r    r!   rj     rk   z,ObjectAliasMixin.classes.<locals>.<dictcomp>rl   rb   r    r    r!   classes  ro   zObjectAliasMixin.classesdict[str, Function]c                 C  rd   )zThe function members.

        This method is part of the consumer API:
        do not use when producing Griffe trees!
        c                 S  re   r    )rf   r   FUNCTIONrh   r    r    r!   rj   $  rk   z.ObjectAliasMixin.functions.<locals>.<dictcomp>rl   rb   r    r    r!   	functions  ro   zObjectAliasMixin.functionsdict[str, Attribute]c                 C  rd   )zThe attribute members.

        This method is part of the consumer API:
        do not use when producing Griffe trees!
        c                 S  re   r    )rf   r   	ATTRIBUTErh   r    r    r!   rj   -  rk   z/ObjectAliasMixin.attributes.<locals>.<dictcomp>rl   rb   r    r    r!   
attributes&  ro   zObjectAliasMixin.attributesdict[str, TypeAlias]c                 C  rd   )zThe type alias members.

        This method is part of the consumer API:
        do not use when producing Griffe trees!
        c                 S  re   r    )rf   r   
TYPE_ALIASrh   r    r    r!   rj   6  rk   z1ObjectAliasMixin.type_aliases.<locals>.<dictcomp>rl   rb   r    r    r!   type_aliases/  ro   zObjectAliasMixin.type_aliasesrM   c                 C  s   | j do	| j S )zGWhether this object/alias is private (starts with `_`) but not special._)r6   
startswith
is_specialrb   r    r    r!   
is_private8  s   zObjectAliasMixin.is_privatec                 C  s   | j do| j dS )z[Whether this object/alias is special ("dunder" attribute/method, starts and end with `__`).__)r6   r}   endswithrb   r    r    r!   r~   =     zObjectAliasMixin.is_specialc                 C  s,   t | jo| jjo| jdo| jd S )zTWhether this object/alias is class-private (starts with `__` and is a class member).r   )rM   r>   ra   r6   r}   r   rb   r    r    r!   is_class_privateB  s   *z!ObjectAliasMixin.is_class_privatec                 C  s   t | jo| j| jjv S )z;Whether this object/alias was imported from another module.)rM   r>   r6   importsrb   r    r    r!   is_importedI  r   zObjectAliasMixin.is_importedc                 C  s,   t | jo| jjot | jjo| j| jjv S )z<Whether this object/alias is exported (listed in `__all__`).)rM   r>   rA   exportsr6   rb   r    r    r!   is_exportedN  s
   
zObjectAliasMixin.is_exportedc                 C  sZ   | j rt| jr| jjsdS | jjdur| j| jjv S | jdr#dS | jp,| j p,| jS )a  Whether this object/alias is exposed to wildcard imports.

        To be exposed to wildcard imports, an object/alias must:

        - be available at runtime
        - have a module as parent
        - be listed in `__all__` if `__all__` is defined
        - or not be private (having a name starting with an underscore)

        Special case for Griffe trees: a submodule is only exposed if its parent imports it.

        Returns:
            True or False.
        FNr|   )	runtimerM   r>   rA   r   r6   r}   r@   r   rb   r    r    r!   is_wildcard_exposedW  s   z$ObjectAliasMixin.is_wildcard_exposedc                 C  sl   | j dur| j S | js| jr| jdsdS | jr*| jjr*t| jjr*| j| jjv S | jr/dS | j	r4dS dS )a  Whether this object is considered public.

        In modules, developers can mark objects as public thanks to the `__all__` variable.
        In classes however, there is no convention or standard to do so.

        Therefore, to decide whether an object is public, we follow this algorithm:

        - If the object's `public` attribute is set (boolean), return its value.
        - If the object is listed in its parent's (a module) `__all__` attribute, it is public.
        - If the parent (module) defines `__all__` and the object is not listed in, it is private.
        - If the object has a private name, it is private.
        - If the object was imported from another module, it is private.
        - Otherwise, the object is public.
        Nr|   TF)
publicr@   rA   r6   r}   r>   rM   r   r   r   rb   r    r    r!   	is_publicw  s   
zObjectAliasMixin.is_publicc                 C  
   t | jS )z"Whether this object is deprecated.)rM   
deprecatedrb   r    r    r!   is_deprecated  s   
zObjectAliasMixin.is_deprecatedc                 C  r   )zWhether this object is generic.)rM   type_parametersrb   r    r    r!   
is_generic  s   
zObjectAliasMixin.is_genericN)r   r`   )r   rc   )r   rp   )r   rs   )r   rv   )r   ry   )r   rM   )r-   r.   r/   r0   propertyr'   rn   rr   ru   rx   r{   r   r~   r   r   r   r   r   r   r   r    r    r    r!   r_      s@    
,r_   )r   r   r   r   )"
__future__r   rR   
contextlibr   typingr   r   r   griffe._internal.enumerationsr   griffe._internal.exceptionsr   r	   r
   griffe._internal.mergerr   collections.abcr   griffe._internal.modelsr   r   r   r   r   r   r   r   r"   r$   r1   r9   rK   r_   r    r    r    r!   <module>   s"   $
27I)