o
    wi                     @  s   U d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
Z
ddlmZ ddl
mZ e	r?dd	lmZmZ dd
l
mZ ee
jjdkZded< ed%ddZeriddlZd&ddZd'ddZd(dd ZdS dd!lmZ d&d"dZd'd#dZd(d$d ZdS ))z<Internal utilities for working with Pydantic types and data.    )annotationsN)suppress)	lru_cache)TYPE_CHECKING)Version)ValidationError)AnyFinal)	BaseModel   zFinal[bool]IS_PYDANTIC_V2clstype[BaseModel]returnstrc                 C  s0   | j d }r|j }r|S td| jd)z.Get the GraphQL typename for a Pydantic model.
typename__z&Cannot extract GraphQL typename from: .)model_fieldsgetdefault	TypeError__qualname__)r   fieldtypename r   I/home/ubuntu/.local/lib/python3.10/site-packages/wandb/_pydantic/utils.pygql_typename   s   r   sstr | bytesr   c                 C  
   t | S )z5Quickly deserialize a JSON string to a Python object.)pydantic_core	from_jsonr   r   r   r   r!   !   s   
r!   vc                 C  s   t j| ddddS )z@Quickly serialize a (possibly Pydantic) object to a JSON string.T)by_alias
round_tripzutf-8)r    to_jsondecoder#   r   r   r   r&   %   s   r&   	classinfo-type[BaseModel] | tuple[type[BaseModel], ...]boolc                   s0   t |trt fdd|D S |}|j S )a  Return True if the object could be parsed into the given Pydantic type.

        This is like a more lenient version of `isinstance()` for use with Pydantic.
        In Pydantic v2, should be fast since the underlying implementation is in Rust,
        and it may be preferable over `try:...except ValidationError:...`.

        See: https://docs.pydantic.dev/latest/api/pydantic_core/#pydantic_core.SchemaValidator.isinstance_python
        c                 3  s    | ]	}|j  V  qd S N)__pydantic_validator__isinstance_python).0r   r(   r   r   	<genexpr>5   s    
z&pydantic_isinstance.<locals>.<genexpr>)
isinstancetupleanyr-   r.   )r#   r)   r   r   r(   r   pydantic_isinstance)   s   
r4   )pydantic_encoderc                 C  r   r,   )jsonloadsr"   r   r   r   r!   B   s   
c                 C  s   t j| tdS )N)r   )r6   dumpsr5   r(   r   r   r   r&   E   s   c              	   C  sZ   t |tr|n|f}|D ]}tt ||  	 W d     dS 1 s%w   Y  qdS )NTF)r1   r2   r   r   model_validate)r#   r)   classesr   r   r   r   r4   H   s   

$)r   r   r   r   )r   r   r   r   )r#   r   r   r   )r#   r   r)   r*   r   r+   )__doc__
__future__r   r6   
contextlibr   	functoolsr   typingr   pydanticpackaging.versionr   r   r   r	   r
   VERSIONmajorr   __annotations__r   r    r!   r&   r4   pydantic.jsonr5   r   r   r   r   <module>   s0    



