
    ii
                    ^   U d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZ d dlmZmZmZmZmZmZmZ 	 d dlmZ eefZded<   n# e$ r efZY nw xY wd dlmZ d d	lmZmZ  ed
          Z e
d          Zd(dZd)dZ d)dZ!d)dZ"d*dZ#d+dZ$d,dZ%d+dZ&d+dZ'd-d Z(d+d!Z)d.d#Z*d/d$Z+d0d&Z,d'S )1    )annotations)isclass)Any
ForwardRefLiteralNewTypeOptionalTypeVarget_args)	AnnotatedNotRequired	ParamSpecRequiredTypeAliasType	TypeGuard
get_origin)r   ztuple[type, ...]AllTypeAliasTypes)TYPE_MAPPING)UNION_TYPESNoneTypePT
annotationr   class_or_tupletype[T] | tuple[type[T], ...]return'TypeGuard[type[T]]'c                    t          |           }|st          |           sdS 	 t          |p| |          S # t          $ r Y dS w xY w)zDetermine whether a given annotation is a subclass of a give type

    :param annotation: A type annotation.
    :param class_or_tuple: A potential super class or classes.

    :returns: A typeguard
    F)get_type_originr   
issubclass	TypeError)r   r   origins      t/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/polyfactory/utils/predicates.pyis_safe_subclassr$      si     Z((F '*-- u&.J???   uus   6 
AA'TypeGuard[Any]'c                    | t           u p@t          | dd          dk    p+t          |           t          v ot           t	          |           v S )zDetermine whether a given annotation is 'typing.Any'.

    :param annotation: A type annotation.

    :returns: A typeguard.
    _name z
typing.Any)r   getattrr   r   r   r   s    r#   is_anyr+   0   sS     	c 	S:w++|;	Sz""k1QcXj=Q=Q6Q    c                $    t          |           dv S )zDetermine whether a given annotation is a valid dict key or value type:
    ``typing.KT`` or ``typing.VT``.

    :returns: A typeguard.
    >   ~KT~VT)strr*   s    r#   is_dict_key_or_value_typer1   >   s     z??n,,r,   c                .    t          |           t          v S )zDetermine whether a given annotation is 'typing.Union'.

    :param annotation: A type annotation.

    :returns: A typeguard.
    )r   r   r*   s    r#   is_unionr3   G   s     :&&+55r,   'TypeGuard[Any | None]'c                    t          |           }|t          u p+t          |           t          v ot          t          |           v S )zDetermine whether a given annotation is 'typing.Optional'.

    :param annotation: A type annotation.

    :returns: A typeguard.
    )r   r	   r   r   r   r   )r   r"   s     r#   is_optionalr6   Q   sB     Z((FXm*Z"8"8K"G"lHX`akXlXlLlmr,   boolc                    t          |           t          u pCt          |                               d          p!t          |                               d          S )zDetermine whether a given annotation is 'typing.Literal'.

    :param annotation: A type annotation.

    :returns: A boolean.
    ztyping.Literalztyping_extensions.Literal)r   r   repr
startswithr*   s    r#   
is_literalr;   \   sY     	
##w. 	D
&&'788	D
&&'BCCr,   'TypeGuard[type[NewType]]'c                "    t          | d          S )zDetermine whether a given annotation is 'typing.NewType'.

    :param annotation: A type annotation.

    :returns: A typeguard.
    __supertype__hasattrr*   s    r#   is_new_typerA   j   s     :///r,   c                .    t          |           t          u S )zDetermine whether a given annotation is 'typing.Annotated'.

    :param annotation: A type annotation.

    :returns: A boolean.
    )r   r   r*   s    r#   is_annotatedrC   t   s     j!!Y..r,   c                N    t          d t          |           D                       S )zDetermine whether any of the types in the given annotation is
    `typing.Annotated`.

    :param annotation: A type annotation.

    :returns: A boolean
    c              3  r   K   | ]2}t          |          pt          |d           ot          |          V  3dS )__args__N)rC   r@   is_any_annotated).0args     r#   	<genexpr>z#is_any_annotated.<locals>.<genexpr>   sX        VYSQgc:66P;KC;P;P     r,   )anyr   r*   s    r#   rG   rG   ~   s;       ]efp]q]q     r,   TypeGuard[TypeAliasType]c                ,    t          | t                    S )zDetermine if the given type annotation is a PEP 695 type alias.

    :param annotation: A type annotation.

    :returns: A boolean
    )
isinstancer   r*   s    r#   is_type_aliasrO      s     j"3444r,   c                B    t          | d          ot          | d          S )zDetermine if the given type annotation is a generic alias.

    :param annotation: A type annotation.

    :returns: A boolean
    
__origin__rF   r?   r*   s    r#   is_generic_aliasrR      s#     :|,,PZ1P1PPr,   TypeGuard[TypeVar]c                ,    t          | t                    S )zDetermine if the given type annotation is a TypeVar.

    Args:
        annotation: A type annotation.

    Returns:
        A boolean.
    )rN   r
   r*   s    r#   is_type_varrU      s     j'***r,   c                    t          |           }|t          t          t          fv rt	          |           d         }t          j        |          x}r|n|S )zGet the type origin of an annotation - safely.

    :param annotation: A type annotation.

    :returns: A type annotation.
    r   )r   r   r   r   r   r   get)r   r"   mapped_types      r#   r   r      sT     
##F)X{333*%%a(*6*:6*B*BB;O;;Or,   TypeGuard[ForwardRef]c                ,    t          | t                    S )zDetermine if the given type annotation is a ForwardRef.

    :param annotation: A type annotation.

    :returns: A boolean.
    )rN   r   r*   s    r#   is_forward_refr[      s     j*---r,   N)r   r   r   r   r   r   )r   r   r   r%   )r   r   r   r4   )r   r   r   r7   )r   r   r   r<   )r   r   r   rL   )r   r   r   rS   )r   r   r   r   )r   r   r   rY   )-
__future__r   inspectr   typingr   r   r   r   r	   r
   r   typing_extensionsr   r   r   r   r   r   r   typing_TypeAliasTyper   __annotations__ImportErrorpolyfactory.constantsr   polyfactory.utils.typesr   r   r   r   r$   r+   r1   r3   r6   r;   rA   rC   rG   rO   rR   rU   r   r[    r,   r#   <module>rf      s   " " " " " " "       Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q                 )<<<<<<+8:N*OOOOOO ) ) )&() / . . . . . 9 9 9 9 9 9 9 9IcNNGCLL   "   - - - -6 6 6 6n n n n   0 0 0 0/ / / /   5 5 5 5Q Q Q Q	+ 	+ 	+ 	+
P 
P 
P 
P. . . . . .s   A AA