U
    	f                     @  s  d dl mZ d dlmZmZmZmZ d dlmZ	 d dl
mZmZmZmZ ddlmZ ddlmZ dd	d
ddZdd	d
ddZdd	d
ddZdd	d
ddZdd	d
ddZdd	d
ddZddd
ddZddddddZdddddd dd!d"d#ZdS )$    )annotations)AnyTypeVarIterablecast)abc)Required	Annotatedget_args
get_origin   )InheritsGeneric)is_uniontypebool)typreturnc                 C  s   t | tkS N)r   r	   r    r   V/var/www/html/apigroqsegura/apigroq/lib/python3.8/site-packages/groq/_utils/_typing.pyis_annotated_type   s    r   c                 C  s   t | p
| tkS r   )r   listr   r   r   r   is_list_type   s    r   c                 C  s   t | p
| }|tkp|tjkS )z)If the given type is `typing.Iterable[T]`)r   r   _c_abc)r   originr   r   r   is_iterable_type   s    r   c                 C  s   t t| S r   )	_is_unionr   r   r   r   r   is_union_type   s    r   c                 C  s   t | tkS r   )r   r   r   r   r   r   is_required_type   s    r   c                 C  s   t | tkS r   )r   r   r   r   r   r   
is_typevar!   s    r    c                 C  s*   t | st| r&tttt| d S | S )Nr   )r   r   strip_annotated_typer   r   r
   r   r   r   r   r!   (   s    r!   int)r   indexr   c              
   C  sX   t | }ztt|| W S  tk
rR } ztd|  d| d|W 5 d }~X Y nX d S )NzExpected type z" to have a type argument at index z but it did not)r
   r   r   
IndexErrorRuntimeError)r   r#   argserrr   r   r   extract_type_arg/   s
    r(   N)failure_messageztuple[type, ...]z
str | None)r   generic_basesr#   r)   r   c                C  s   t tt| p| }||kr$t| |S t|trd}|jD ]}|j|kr8|} qPq8|dkrntd| d| dt||}t	|rt| |S |S t|pd| d|  dS )a  Given a type like `Foo[T]`, returns the generic type variable `T`.

    This also handles the case where a concrete subclass is given, e.g.
    ```py
    class MyResponse(Foo[bytes]):
        ...

    extract_type_var(MyResponse, bases=(Foo,), index=0) -> bytes
    ```

    And where a generic subclass is given:
    ```py
    _T = TypeVar('_T')
    class MyResponse(Foo[_T]):
        ...

    extract_type_var(MyResponse[bytes], bases=(Foo,), index=0) -> bytes
    ```
    NzFCould not find the generic base class;
This should never happen;
Does z inherit from one of z ?z/Could not resolve inner type variable at index z for )
r   objectr   r(   
isinstancer   __orig_bases__
__origin__r%   r    )r   r*   r#   r)   clsZtarget_base_classbaseZ	extractedr   r   r   extract_type_var_from_base7   s$    




	
r1   )
__future__r   typingr   r   r   r   collectionsr   r   typing_extensionsr   r	   r
   r   _typesr   _compatr   r   r   r   r   r   r   r    r!   r(   r1   r   r   r   r   <module>   s   