o
    ùT·j²  ã                   @  s6  U d dl mZ d dlZd dlZd dl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mZ ddlmZ dd	lmZ dd
lmZ d4dd„Zd4dd„Zd4dd„Zd4dd„Zd4dd„Zd4dd„Zd4dd„ZejfZ de!d< ej"dkr}g e ¢ej‘R Z d5d#d$„Z#ed%d&�d6d'd(„ƒZ$d7d+d,„Z%dd-œd8d2d3„Z&dS )9é    )ÚannotationsN)ÚAnyÚTypeVarÚIterableÚcast)Úabc)ÚTypeIsÚRequiredÚ	AnnotatedÚget_argsÚ
get_originé   )Ú	lru_cacheé   )ÚInheritsGeneric)Úis_unionÚtypÚtypeÚreturnÚboolc                 C  ó   t | ƒtkS ©N)r   r
   ©r   © r   úX/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/openai/_utils/_typing.pyÚis_annotated_type   ó   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jkp|tjkp|tjkS r   )r   Útyping_extensionsÚSequenceÚtypingÚ_c_abc©r   Úoriginr   r   r   Úis_sequence_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   r"   r#   r   r   r   Úis_iterable_type"   s   r&   c                 C  s   t t| ƒƒS r   )Ú	_is_unionr   r   r   r   r   Úis_union_type(   r   r(   c                 C  r   r   )r   r	   r   r   r   r   Úis_required_type,   r   r)   c                 C  r   r   )r   r   r   r   r   r   Ú
is_typevar0   s   r*   z1tuple[type[typing_extensions.TypeAliasType], ...]Ú_TYPE_ALIAS_TYPES)é   é   Útpr   ú'TypeIs[typing_extensions.TypeAliasType]c                C  s
   t | tƒS )zìReturn whether the provided argument is an instance of `TypeAliasType`.

    ```python
    type Int = int
    is_type_alias_type(Int)
    # > True
    Str = TypeAliasType("Str", str)
    is_type_alias_type(Str)
    # > True
    ```
    )Ú
isinstancer+   )r.   r   r   r   Úis_type_alias_type;   s   
r1   i   )Úmaxsizec                 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   r3   K   s   r3   ÚindexÚintc              
   C  sJ   t | ƒ}ztt|| ƒW S  ty$ } ztd| › d|› d�ƒ|‚d }~ww )NzExpected type z" to have a type argument at index z but it did not)r   r   r   Ú
IndexErrorÚRuntimeError)r   r4   ÚargsÚerrr   r   r   Úextract_type_argS   s   €ÿr:   )Úfailure_messageÚgeneric_basesútuple[type, ...]r;   ú
str | Nonec                C  s¦   t tt| ƒp| ƒ}||v rt| |ƒS t|tƒrGd}|jD ]}|j|v r'|} nq|du r7td|› d|› d�ƒ‚t||ƒ}t	|ƒrEt| |ƒS |S t|pQd|› d| › �ƒ‚)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:   r0   r   Ú__orig_bases__Ú
__origin__r7   r*   )r   r<   r4   r;   ÚclsÚtarget_base_classÚbaseÚ	extractedr   r   r   Úextract_type_var_from_base[   s.   



þþþÿ

	rF   )r   r   r   r   )r.   r   r   r/   )r   r   r   r   )r   r   r4   r5   r   r   )
r   r   r<   r=   r4   r5   r;   r>   r   r   )'Ú
__future__r   Úsysr!   r   r   r   r   r   Úcollectionsr   r"   r   r	   r
   r   r   Ú_utilsr   Ú_typesr   Ú_compatr   r'   r   r   r%   r&   r(   r)   r*   ÚTypeAliasTyper+   Ú__annotations__Úversion_infor1   r3   r:   rF   r   r   r   r   Ú<module>   s4    









û