
    gsG                       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rd dlmZ d d	lmZmZmZmZmZmZ  ed
      ZddZ G d d      Z G d d      Z G d d      Z G d d      Z G d deeee      Z y)    )annotationsN)suppress)TYPE_CHECKINGAnyTypeVar)Kind)AliasResolutionErrorBuiltinModuleErrorCyclicAliasError)merge_stubs)Sequence)Alias	AttributeClassFunctionModuleObject_ObjTypec                    t        | t              r| st        d      | j                  d      }nt	        |       }|st        d      |S )NzEmpty strings are not supported.zEmpty tuples are not supported)
isinstancestr
ValueErrorsplitlist)keypartss     C/var/www/openai/venv/lib/python3.12/site-packages/_griffe/mixins.py
_get_partsr      sE    #s>??		#S	9::L    c                       e Zd ZdZddZddZy)GetMembersMixinzMixin class to share methods for accessing members.

    Methods:
        get_member: Get a member with its name or path.
        __getitem__: Same as `get_member`, with the item syntax `[]`.
    c                    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   s      r   __getitem__zGetMembersMixin.__getitem__*   sM    " 3u:?##E!H--a)%)44r    c                    t        |      }t        |      dk(  r| j                  |d      S | j                  |d      j                  |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'   s      r   r,   zGetMembersMixin.get_member@   sO    " 3u:?<<a))||E!H%00qr;;r    N)r   str | Sequence[str]returnr   )__name__
__module____qualname____doc__r)   r,    r    r   r"   r"   "   s    5,<r    r"   c                       e Zd ZdZddZddZy)DelMembersMixinzMixin class to share methods for deleting members.

    Methods:
        del_member: Delete a member with its name or path.
        __delitem__: Same as `del_member`, with the item syntax `[]`.
    c                    t        |      }t        |      dk(  r|d   }	 | j                  |= y| j
                  |d      |dd = y# t        $ r | j                  |= Y yw xY w)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   names       r   __delitem__zDelMembersMixin.__delitem__a   sp    " 3u:?8D1LL&   q*595  1**401s   A AAc                    t        |      }t        |      dk(  r|d   }| j                  |= y| j                  |d      j                  |dd        y)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_memberr9   s       r   r=   zDelMembersMixin.del_member|   sN    " 3u:?8DT"LLq"--eABi8r    N)r   r-   r.   None)r/   r0   r1   r2   r;   r=   r3   r    r   r5   r5   Y   s    669r    r5   c                       e Zd ZdZddZddZy)SetMembersMixinzMixin class to share methods for setting members.

    Methods:
        set_member: Set a member with its name or path.
        __setitem__: Same as `set_member`, with the item syntax `[]`.
    c                    t        |      }t        |      dk(  r0|d   }|| j                  |<   | j                  r| |_        y| |_        y|| j                  |d      |dd <   y)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   valuer   r:   s        r   __setitem__zSetMembersMixin.__setitem__   sd     3u:?8D!&DLL!!,0)#05DLLq"59-r    c                   t        |      }t        |      dk(  r&|d   }|| j                  v r| j                  |   }|j                  s|j                  r|j
                  sw|j                  skt        t        t        t              5  |j                  r=|j                  |j                  k7  r$t        t              5  t        ||      }ddd       ddd       |j                  j                         D ]!  }t        t              5  ||_        ddd       # || j                  |<   | j"                  r| |_        y| |_        y| j                  |d      j)                  |dd |       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)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targetrB   rC   rD   
set_member)r(   r   rE   r   r:   memberaliass          r   rP   zSetMembersMixin.set_member   s<     3u:?8Dt||#d+ ''1L1LPVPnPn &&:<LN`a$5>>V__3T%-j%9,7,FE &: b "(!6!6!8%&67+0EL 87 "9 "'DLL!!,0)#LLq"--eABi? &:%9 ba
 87s0   5E3;E'E3E?'E0	,E33E<?F	N)r   r-   rE   zObject | Aliasr.   r>   )r/   r0   r1   r2   rF   rP   r3   r    r   r@   r@      s    64)@r    r@   c                  0    e Zd ZdZddddZedd       Zy)	SerializationMixinzMixin class to share methods for de/serializing objects.

    Methods:
        as_json: Return this object's data as a JSON string.
        from_json: Create an instance of this class from a JSON string.
    F)fullc               @    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)clsrU   )_griffe.encodersrW   jsondumps)r(   rU   kwargsrW   s       r   as_jsonzSerializationMixin.as_json   s"     	1zz$EKdEfEEr    c                    ddl m} |j                  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 )rY   r_   
setdefaultrZ   loadsr   	TypeError)rX   json_stringr\   r_   objs        r   	from_jsonzSerializationMixin.from_json   sL     	2-6jj//#s#B3%HII
r    N)rU   boolr\   r   r.   r   )rX   ztype[_ObjType]rd   r   r\   r   r.   r   )r/   r0   r1   r2   r]   classmethodrf   r3   r    r   rT   rT      s&     ', F  r    rT   c                      e Zd Z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y)ObjectAliasMixina  Mixin class to share methods that appear both in objects and aliases, unchanged.

    Attributes:
        all_members: All members (declared and inherited).
        modules: The module members.
        classes: The class members.
        functions: The function members.
        attributes: The attribute members.
        is_private: Whether this object/alias is private (starts with `_`) but not special.
        is_class_private: Whether this object/alias is class-private (starts with `__` and is a class member).
        is_special: Whether this object/alias is special ("dunder" attribute/method, starts and end with `__`).
        is_imported: Whether this object/alias was imported from another module.
        is_exported: Whether this object/alias is exported (listed in `__all__`).
        is_wildcard_exposed: Whether this object/alias is exposed to wildcard imports.
        is_public: Whether this object is considered public.
        is_deprecated: Whether this object is deprecated.
    c                f    | 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_classr8   r+   r(   s    r   r&   zObjectAliasMixin.all_members$  s/     ===d,,===||r    c                    | j                   j                         D ci c]%  \  }}|j                  t        j                  u s#||' c}}S c c}}w )z~The module members.

        This method is part of the consumer API:
        do not use when producing Griffe trees!
        )r&   itemskindr   MODULEr(   r:   rQ   s      r   moduleszObjectAliasMixin.modules/  sG     261A1A1G1G1Ih1IvV[[\`\g\gMgf1Ihhh   $AAc                    | j                   j                         D ci c]%  \  }}|j                  t        j                  u s#||' c}}S c c}}w )z}The class members.

        This method is part of the consumer API:
        do not use when producing Griffe trees!
        )r&   ro   rp   r   CLASSrr   s      r   classeszObjectAliasMixin.classes8  sG     261A1A1G1G1Ig1IvV[[\`\f\fMff1Igggrt   c                    | j                   j                         D ci c]%  \  }}|j                  t        j                  u s#||' c}}S c c}}w )zThe function members.

        This method is part of the consumer API:
        do not use when producing Griffe trees!
        )r&   ro   rp   r   FUNCTIONrr   s      r   	functionszObjectAliasMixin.functionsA  sG     261A1A1G1G1Ij1IvV[[\`\i\iMif1Ijjjrt   c                    | j                   j                         D ci c]%  \  }}|j                  t        j                  u s#||' c}}S c c}}w )zThe attribute members.

        This method is part of the consumer API:
        do not use when producing Griffe trees!
        )r&   ro   rp   r   	ATTRIBUTErr   s      r   
attributeszObjectAliasMixin.attributesJ  sG     261A1A1G1G1Ik1IvV[[\`\j\jMjf1Ikkkrt   c                V    | j                   j                  d      xr | j                   S )zGWhether this object/alias is private (starts with `_`) but not special._)r:   
startswith
is_specialrm   s    r   
is_privatezObjectAliasMixin.is_privateS  s%     yy##C(@-@@r    c                r    | j                   j                  d      xr | j                   j                  d      S )z[Whether this object/alias is special ("dunder" attribute/method, starts and end with `__`).__)r:   r   endswithrm   s    r   r   zObjectAliasMixin.is_specialX  s-     yy##D)Fdii.@.@.FFr    c                    | j                   xrQ | j                   j                  xr9 | j                  j                  d      xr | j                  j	                  d       S )zTWhether this object/alias is class-private (starts with `__` and is a class member).r   )rD   rl   r:   r   r   rm   s    r   is_class_privatez!ObjectAliasMixin.is_class_private]  sL     {{st{{33s		8L8LT8Rs[_[d[d[m[mnr[sWssr    c                b    | j                   xr" | j                  | j                   j                  v S )z;Whether this object/alias was imported from another module.)rD   r:   importsrm   s    r   is_importedzObjectAliasMixin.is_importedb  s&     {{?tyyDKK,?,???r    c                    | j                   j                  xrC t        | j                   j                  xr" | j                  | j                   j                  v       S )z<Whether this object/alias is exported (listed in `__all__`).)rD   rI   rg   exportsr:   rm   s    r   is_exportedzObjectAliasMixin.is_exportedg  sC     {{$$gdkk.A.A.fdiiSWS^S^SfSfFf)ggr    c                B   | j                   r| j                  j                  sy| j                  j                  "| j                  | j                  j                  v S | j                  j                  d      ry| j                  xs | j                   xs | 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.
        Fr   )runtimerD   rI   r   r:   r   rH   r   rm   s    r   is_wildcard_exposedz$ObjectAliasMixin.is_wildcard_exposedl  s    " ||4;;#8#8 ;;*99 3 333 99$ }}FDNN 2Fd6F6FFr    c                   | j                   | j                   S | j                  s(| j                  r| j                  j	                  d      sy| j
                  rW| j
                  j                  rAt        | j
                  j                        r"| j                  | j
                  j                  v S | j                  ry| j                  ryy)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.
        r   TF)
publicrH   rI   r:   r   rD   rg   r   r   r   rm   s    r   	is_publiczObjectAliasMixin.is_public  s    " ;;";; }}		8L8LS8Q ;;4;;00T$++:M:M5N99 3 333
 ??
  r    c                ,    t        | j                        S )z"Whether this object is deprecated.)rg   
deprecatedrm   s    r   is_deprecatedzObjectAliasMixin.is_deprecated  s     DOO$$r    N)r.   zdict[str, Object | Alias])r.   zdict[str, Module])r.   zdict[str, Class])r.   zdict[str, Function])r.   zdict[str, Attribute])r.   rg   )r/   r0   r1   r2   propertyr&   rs   rw   rz   r}   r   r   r   r   r   r   r   r   r3   r    r   rj   rj     s    $   i i h h k k l l A A G G t t @ @ h h G G> * *X % %r    rj   )r   r-   r.   zSequence[str])!
__future__r   rZ   
contextlibr   typingr   r   r   _griffe.enumerationsr   _griffe.exceptionsr	   r
   r   _griffe.mergerr   collections.abcr   _griffe.modelsr   r   r   r   r   r   r   r   r"   r5   r@   rT   rj   r3   r    r   <module>r      s    #   . . % Y Y &(PP:	2< 2<n99 99xK@ K@\+ +\l%J\ l%r    