o
    ۷iB                     @   sh   d Z ddlmZmZmZmZmZmZmZm	Z	m
Z
 dedeeedf B defddZdedefd	d
ZdS )zE
Typing utilities: Utilities related to type checking and validation
    )	AnyDictListSetTupleTypeUnionget_args
get_originobjclass_or_tuple.returnc                    s   t |ts|f}g }|D ]}t|tu r|t| q|| qt|}t|v r,dS t } fdd|D }dd |D }d|v rFdS |t	t
fv rWt fdd|D S |tu rft fdd|D S |tu rut fd	d|D S d
S )z
    Checks if an object is an instance of any of the provided types. For collections, it checks if every element is of
    the correct type as well.
    Tc                    s"   h | ]}t  t|p|r|qS  )
isinstancer
   .0tr   r   R/home/ubuntu/vllm_env/lib/python3.10/site-packages/diffusers/utils/typing_utils.py	<setcomp>+   s   " z!_is_valid_type.<locals>.<setcomp>c                 S      h | ]}t |qS r   )r	   r   r   r   r   r   /       r   c                 3   s&    | ] t  fd dD V  qdS )c                 3   s    | ]}t | V  qd S N_is_valid_typer   xr   r   r   	<genexpr>4   s    +_is_valid_type.<locals>.<genexpr>.<genexpr>N)allr   r   r   r   r   4   s   $ z!_is_valid_type.<locals>.<genexpr>c                 3   sf    | ]. t  d kr d tu rt fddD p.t t  ko.tdd t D V  qdS )   c                 3   s    | ]
}t | d  V  qdS )r   Nr   r   r   r   r   r   9       r   c                 s   s    | ]
\}}t ||V  qd S r   r   )r   r   ttr   r   r   r   <   r$   N)lenEllipsisr    zipr!   r   r   r   r   7   s    .&
c                 3   s0    | ]\ t  fd d D V  qdS )c                 3   s(    | ]\}}t | ot |V  qd S r   r   )r   kvktvtr   r   r   B   s   & r   N)r    itemsr!   r   r+   r   r   A   s
    
F)r   tupler
   r   extendr	   appendr   typelistsetanydict)r   r   unpacked_class_or_tupler   obj_typeelem_class_or_tupler   r   r   r      s4   
	r   c                 C   s   t | }|ttfv r!|tu rtnt}ttdd | D  }|| S |tu r0ttdd | D  S |tu rTttdd | 	 D  }ttdd | 
 D  }t||f S |S )zU
    Gets a detailed type for an object, including nested types for collections.
    c                 S   r   r   _get_detailed_typer   r   r   r   r   R   r   z%_get_detailed_type.<locals>.<setcomp>c                 s   s    | ]}t |V  qd S r   r:   r   r   r   r   r   U   s    z%_get_detailed_type.<locals>.<genexpr>c                 S   r   r   r:   r   r)   r   r   r   r   W   r   c                 S   r   r   r:   r<   r   r   r   r   X   r   )r2   r3   r4   r   r   r   r/   r   r6   keysvaluesr   )r   r8   obj_origin_type
elems_type	keys_typevalues_typer   r   r   r;   J   s   r;   N)__doc__typingr   r   r   r   r   r   r   r	   r
   r/   boolr   r;   r   r   r   r   <module>   s   ,"5