
    biH                     l    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edf   f   defdZdedefdZy	)
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           	      J    t        |t              s|f}g }|D ]?  }t        |      t        u r|j	                  t        |             /|j                  |       A t        |      }t        |v ryt               }|D ch c]  }t         t        |      xs |      s|  }}|D ch c]  }t        |       }}d|v ry|t        t        fv rt         fd|D              S |t        u rt         fd|D              S |t        u rt         fd|D              S yc c}w c c}w )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.
    T c              3   H   K   | ]  t        fd D                yw)c              3   6   K   | ]  }t        |        y wN_is_valid_type.0xts     W/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/diffusers/utils/typing_utils.py	<genexpr>z+_is_valid_type.<locals>.<genexpr>.<genexpr>4   s     9~a+9s   N)allr   r   r   s    @r   r   z!_is_valid_type.<locals>.<genexpr>4   s     Wa39S99Ws   "c              3      K   | ]l  t              d k(  xr! d   t        u xr t        fdD              xs5 t              t              k(  xr t        d t              D               n yw)   c              3   <   K   | ]  }t        |d            yw)r   Nr   r   s     r   r   z+_is_valid_type.<locals>.<genexpr>.<genexpr>9   s     6\ST~a17N6\s   c              3   :   K   | ]  \  }}t        ||        y wr   r   )r   r   tts      r   r   z+_is_valid_type.<locals>.<genexpr>.<genexpr><   s     'W%!Rq"(='Ws   N)lenEllipsisr   zipr   s    @r   r   z!_is_valid_type.<locals>.<genexpr>7   sw      
 	 Vq[\QrUh.\36\X[6\3\ Y XQWC'W3sTU;'W$WY
s   A2A6c              3   n   K   | ]*  \  t        fd j                         D               , yw)c              3   X   K   | ]!  \  }}t        |      xr t        |       # y wr   r   )r   kvktvts      r   r   z+_is_valid_type.<locals>.<genexpr>.<genexpr>B   s+     XDAqq"%?.B*??Xs   '*N)r   items)r   r+   r,   r   s    @@r   r   z!_is_valid_type.<locals>.<genexpr>A   s.      
B XCIIKXX
s   05F)
isinstancetupler   r	   extendr
   appendr   typelistsetanydict)r   r   unpacked_class_or_tupler   obj_typeelem_class_or_tuples   `     r   r   r      s>   
 ne,(* ! .a=E!#**8A;7#**1-	.
 23N
nCyH!/WA:c:a=CUTU3VaWNW 1??18A;??	  	dC[	 WCVWWW	U	 
 )
 
 	
 
T	 
-
 
 	
 9 X @s   >DD'D c           	         t        |       }|t        t        fv rB|t        u rt        nt        }t
        t        | D ch c]  }t        |       c}         }||   S |t        u rt        t        d | D                 S |t        u ryt
        t        | j                         D ch c]  }t        |       c}         }t
        t        | j                         D ch c]  }t        |       c}         }t        ||f   S |S c c}w c c}w c c}w )zU
    Gets a detailed type for an object, including nested types for collections.
    c              3   2   K   | ]  }t        |        y wr   )_get_detailed_type)r   r   s     r   r   z%_get_detailed_type.<locals>.<genexpr>U   s     >Q-a0>s   )r2   r3   r4   r   r   r	   r/   r<   r   r6   keysvaluesr   )r   r8   obj_origin_typer   
elems_typer)   	keys_typevalues_types           r   r<   r<   J   s     CyHD#;"*d"2$5!EA"4Q"7!EFG
z**	U	U>#>>??	T	%
 K1!3A!6 KLM	E#**,"OQ#5a#8"OPQI{*++ "F
 !L"Os   D 
!D
D

N)__doc__typingr   r   r   r   r   r   r	   r
   r   boolr   r<   r       r   <module>rG      sW    R Q Q2 2U4tSy9I3I-J 2t 2jC D rF   