
    gB                         U d Z ddlZddlmZmZmZmZmZmZm	Z	m
Z
mZ e	gZee   ed<   ej                  dk\  rddlmZ eegz  Zed   Z ede	      Zeeee ed      fZd
edefdZdedefdZdedefdZy)z4Handle typing imports based on system compatibility.    N)	AnyCallableListLiteralTypeTypeVarUnionget_args
get_originUNION_TYPES)   
   )	UnionType)GETOPTIONSHEADPOSTPUTPATCHDELETE	CallableT)boundobjreturnc                    	 t        | t              ryt        | t        t        f      rt	        d | D              S t        | t
              r t	        d | j                         D              S t        | d      ryy# t        $ r Y yw xY w)a  Check if an object is JSON serializable.

    This is a weak check, as it does not check for the actual JSON serialization, but only for the types of the object.
    It works correctly for basic use cases but do not guarantee an exhaustive check.

    Object is considered to be recursively json serializable if:
    - it is an instance of int, float, str, bool, or NoneType
    - it is a list or tuple and all its items are json serializable
    - it is a dict and all its keys are strings and all its values are json serializable
    Tc              3   2   K   | ]  }t        |        y wN)is_jsonable).0items     R/var/www/openai/venv/lib/python3.12/site-packages/huggingface_hub/utils/_typing.py	<genexpr>zis_jsonable.<locals>.<genexpr>3   s     9ST{4(Ss   c              3   \   K   | ]$  \  }}t        |t              xr t        |       & y wr   )
isinstancestrr   )r   keyvalues      r!   r"   zis_jsonable.<locals>.<genexpr>5   s+     aU`zsEz#s+BE0BBU`s   *,__json__F)	r$   _JSON_SERIALIZABLE_TYPESlisttuplealldictitemshasattrRecursionError)r   s    r!   r   r   $   s{    c34cD%=)9S999c4 aUXU^U^U`aaa3
# s!   A9 'A9 /A9 +A9 9	BBtype_c                 t    t        |       t        v r't        |       }t        |      dk(  rt	        d      |v ryy)zyCheck if a type is optional, i.e. Optional[Type] or Union[Type, None] or Type | None, where Type is a non-composite type.   NTF)r   r   r
   lentype)r1   
union_argss     r!   is_simple_optional_typer7   =   s5    %K'e_
z?aDJ*$<    optional_typec                 b    t        |       D ]  }|t        d      us|c S  t        d|  d      )zFUnwraps a simple optional type, i.e. returns Type from Optional[Type].N'z' is not an optional type)r
   r5   
ValueError)r9   args     r!   unwrap_simple_optional_typer>   F   s9    &d4j J ' q'@A
BBr8   )__doc__systypingr   r   r   r   r   r   r	   r
   r   r   __annotations__version_infotypesr   HTTP_METHOD_Tr   intfloatr%   boolr5   r)   r   r7   r>    r8   r!   <module>rJ      s    ; 
 [ [ [  T#Y  wI;K RS Kx0	T4:> S T 24 D Ct C Cr8   