o
    -wi
                     @  s  U d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	 ddl
Z
ddl
mZmZ ddlmZ ejZe
jd^ZZeed	kZd
ed< e	e Zded< d#ddZerjd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)AnyType)	BaseModelValidationError)	TypeAlias.   boolIS_PYDANTIC_V2r   BaseModelType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: r	   )model_fieldsgetdefault	TypeError__qualname__)r   fieldtypename r   R/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/wandb/_pydantic/utils.pygql_typename   s   r   sr   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)BaseModelType | tuple[BaseModelType, ...]c                   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   
r2   )pydantic_encoderc                 C  r   r*   )jsonloadsr!   r   r   r   r    B   s   
c                 C  s   t j| tdS )N)r   )r4   dumpsr3   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)r/   r0   r   r   model_validate)r"   r(   classesr   r   r   r   r2   H   s   

$)r   r   r   r   )r   r   r   r   )r"   r   r   r   )r"   r   r(   r)   r   r   ) __doc__
__future__r   r4   sys
contextlibr   typingr   r   pydanticr   r   typing_extensionsr   version_infoPYTHON_VERSIONVERSIONsplitpydantic_major_intr   __annotations__r   r   r   r    r%   r2   pydantic.jsonr3   r   r   r   r   <module>   s.    




