o
    $6d@                     @  sJ  U d Z ddlmZ ddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ ddlmZmZmZ ddlmZmZmZmZmZmZmZ erOd	d
lmZ zddlmZ W n eyf   ddlmZ Y nw eZejdk rqdZnddlm Z ejdk rddlm!Z!m"Z" nddlm!Z!m"Z" ejdk rdzddZ#efZ$ndzddZ#ej%ej ej&fZ$ejdk re'dZ(e'e)Z*nddlm(Z( ehZ+de,d< e-edre+.ej de(gdd e+D R Z/d e,d!< eZ0d{d$d%Z1d|d'd(Z2d|d)d*Z3d}d+d,Z4d~d.d/Z5dd1d2Z6d|d3d4Z7e8d5e9Z:d|d6d7Z;dd9d:Z<dd;d<Z=dd=d>Z>dd?d@Z?dAdBddFdGZ@dddKdLZAdddOdPZBdddQdRZCddUdVZDdddWdd]d^ZEejd_k s_dej  kr]d`k rjn n	addbdcddhdiZFnejZFejdkrwejGZGn	 ejH			bdddkdlZGejdk r	dddodpZIn	dddqdpZIddtduZJddxdyZKdS )zoLogic for interacting with type annotations, mostly extensions, shims and hacks to wrap python's typing module.    )annotationsN)Callable)partial)GetSetDescriptorType)TYPE_CHECKINGAny
ForwardRef)	AnnotatedFinalLiteralTypeAliasType	TypeGuardget_args
get_origin   )StandardDataclass)_TypingBase)_Final)   	    )GenericAlias)r      )NotRequiredRequired)r   
   tptype[Any] | Nonereturnboolc                 C  s
   | t ju S N)typingUnionr   r   r   wC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\pydantic/_internal/_typing_extra.pyorigin_is_union)      
r%   c                 C  s   | t ju p	| tju S r    )r!   r"   types	UnionTyper#   r   r   r$   r%   0      )NoneTypezset[Any]LITERAL_TYPESr   c                 c  s    | ]}|d  V  qd S r    r   ).0r   r   r   r$   	<genexpr>A   s    r-   tuple[Any, ...]
NONE_TYPEStype_r   c                 C  s   | t v S r    )r/   r0   r   r   r$   is_none_typeG      r2   	type[Any]c                 C  s   | t u p	t| t u S r    )r   r   r1   r   r   r$   is_callable_typeK   r)   r5   c                 C  s   t d uo	t| tv S r    )r   r   r+   r1   r   r   r$   is_literal_typeO   r)   r6   c                 C  s   t | S r    )r   r1   r   r   r$   literal_valuesS   r3   r7   	list[Any]c                 C  s(   t | s| gS t| }tdd |D S )zThis method is used to retrieve all Literal values as
    Literal can be used recursively (see https://www.python.org/dev/peps/pep-0586)
    e.g. `Literal[Literal[Literal[1, 2, 3], "foo"], 5, None]`.
    c                 s  s"    | ]}t |D ]}|V  qqd S r    )all_literal_values)r,   valuexr   r   r$   r-   `   s     z%all_literal_values.<locals>.<genexpr>)r6   r7   list)r0   valuesr   r   r$   r9   W   s   r9   ann_typec                 C  s&   ddl m} t| }|d uo||tS )Nr   lenient_issubclass)_utilsr@   r   r	   )r>   r@   originr   r   r$   is_annotatedc   s   rC   c                 C  s    ddl m} || tot| dS )zuCheck if a given class is a named tuple.
    It can be either a `typing.NamedTuple` or `collections.namedtuple`.
    r   r?   _fields)rA   r@   tuplehasattr)r0   r@   r   r   r$   is_namedtuplej   s   rG   test_new_typec                 C  s   t | tjo
t| dS )zlCheck whether type_ was created using typing.NewType.

    Can't use isinstance because it fails <3.10.
    __supertype__)
isinstancerH   	__class__rF   r1   r   r   r$   is_new_typev   s   rL   vc                 C  s*   | d u rdS | j tjj kot| dd dkS )NF_nameClassVar)rK   r!   rO   getattrrM   r   r   r$   _check_classvar~   s   rR   c                 C  s8   t | s
t t| rdS | jtjkr| jdrdS dS )NTz	ClassVar[F)rR   r   rK   r!   r   __forward_arg__
startswithr>   r   r   r$   is_classvar   s
   rV   c                 C  s2   | du rdS | j tj kotjdk pt| dddkS )z/Check if a given type is a `typing.Final` type.NF)r      rN   r
   )rK   r
   sysversion_inforP   rQ   r   r   r$   _check_finalvar   s   &rZ   c                 C  s   t | p	t t| S r    )rZ   r   rU   r   r   r$   is_finalvar   r)   r[      )parent_depthr]   intdict[str, Any] | Nonec                 C  s   t | }|jdu rdS |jS )a  We allow use of items in parent namespace to get around the issue with `get_type_hints` only looking in the
    global module namespace. See https://github.com/pydantic/pydantic/issues/2678#issuecomment-1008139014 -> Scope
    and suggestion at the end of the next comment by @gvanrossum.

    WARNING 1: it matters exactly where this is called. By default, this function will build a namespace from the
    parent of where it is called.

    WARNING 2: this only looks in the parent namespace, not other parents since (AFAIK) there's no way to collect a
    dict of exactly what's in scope. Using `f_back` would work sometimes but would be very wrong and confusing in many
    other cases. See https://discuss.python.org/t/is-there-a-way-to-access-parent-nested-namespaces/20659.
    N)rX   	_getframef_backf_locals)r]   framer   r   r$   parent_frame_namespace   s   

rd   objglobalnsdict[str, Any]c                 C  sT   t | dd }|r&ztj| j}W n	 ty   Y nw |r"i ||S | S |p)i S )N
__module__)rP   rX   modules__dict__KeyErrorcopy)re   rf   module_nameZmodule_globalnsr   r   r$   add_module_globals   s   rn   clsparent_namespacec                 C  s   t | |}| || j< |S r    )rn   __name__)ro   rp   nsr   r   r$   get_cls_types_namespace   s   

rs   c                 C  sb   i }t | jD ]'}|jd}tt|}|dur.|tur.| D ]\}}t|||||< q!q|S )zCollect annotations from a class, including those from parent classes.

    Unlike `typing.get_type_hints`, this function will not error if a forward reference is not resolvable.
    __annotations__N)	reversed__mro__rj   getdictvarsr   itemseval_type_lenient)re   rf   hintsbaseannlocalnsnamer:   r   r   r$   get_cls_type_hints_lenient   s   r   r:   r   c                 C  sN   | du rt } nt| trt| ddd} zt| ||W S  ty&   |  Y S w )zhBehaves like typing._eval_type, except it won't raise an error if a forward reference can't be resolved.NFTis_argumentis_class)r*   rJ   str_make_forward_refr!   
_eval_type	NameError)r:   rf   r   r   r   r$   r{      s   
r{   )include_keystypes_namespacefunctionCallable[..., Any]r   set[str] | Noner   c                C  s   t | tr
| jj}n| j}t| }i }| D ]&\}}|dur$||vr$q|du r+t}n	t |tr4t|}t	
|||||< q|S )zLike `typing.get_type_hints`, but doesn't convert `X` to `Optional[X]` if the default value is `None`, also
    copes with `partial`.
    N)rJ   r   funcrt   rn   rz   r*   r   r   r!   r   )r   r   r   r   rf   Z
type_hintsr   r:   r   r   r$   get_function_type_hints   s   


r   )r   r   rW   )r   r   r   TF)r   argr   r   typing.ForwardRefc                C  s   t | |S )a5  Wrapper for ForwardRef that accounts for the `is_class` argument missing in older versions.
        The `module` argument is omitted as it breaks <3.9.8, =3.10.0 and isn't used in the calls below.

        See https://github.com/python/cpython/pull/28560 for some background.
        The backport happened on 3.9.8, see:
        https://github.com/pydantic/pydantic/discussions/6244#discussioncomment-6275458,
        and on 3.10.1 for the 3.10 branch, see:
        https://github.com/pydantic/pydantic/issues/6912

        Implemented as EAFP with memory.
        )r!   r   )r   r   r   r   r   r$   r     s   r   include_extrasc                 C  sJ  t | ddri S t| tri }t| jD ]e}|du r't tj|jddi }n|}|j	di }t|t
jr8i }|du rBtt|n|}|du rQ|du rQ||}}| D ]#\}	}
|
du ratd}
t|
trmt|
ddd}
t|
||}
|
||	< qUq|r~|S dd	 | D S |du rt| t
jr| j	}n| }t|d
r|j}t|d
st |di }|du r|}n|du r|}t | dd}|du rt| tjri S t| dt| }t|}| D ]9\}	}
|
du rtd}
t|
trt|
t| t
j dd}
t|
||}
|	|v r||	 du rtj|
 }
|
||	< q|r|S dd	 | D S )a  Taken verbatim from python 3.10.8 unchanged, except:
        * type annotations of the function definition above.
        * prefixing `typing.` where appropriate
        * Use `_make_forward_ref` instead of `typing.ForwardRef` to handle the `is_class` argument.

        https://github.com/python/cpython/blob/aaaf5174241496afca7ce4d4584570190ff972fe/Lib/typing.py#L1773-L1875

        DO NOT CHANGE THIS METHOD UNLESS ABSOLUTELY NECESSARY.
        ======================================================

        Return type hints for an object.

        This is often the same as obj.__annotations__, but it handles
        forward references encoded as string literals, adds Optional[t] if a
        default value equal to None is set and recursively replaces all
        'Annotated[T, ...]' with 'T' (unless 'include_extras=True').

        The argument may be a module, class, method, or function. The annotations
        are returned as a dictionary. For classes, annotations include also
        inherited members.

        TypeError is raised if the argument is not of a type that can contain
        annotations, and an empty dictionary is returned if no annotations are
        present.

        BEWARE -- the behavior of globalns and localns is counterintuitive
        (unless you are familiar with how eval() and exec() work).  The
        search order is locals first, then globals.

        - If no dict arguments are passed, an attempt is made to use the
          globals from obj (or the respective module's globals for classes),
          and these are also used as the locals.  If the object does not appear
          to have globals, an empty dictionary is used.  For classes, the search
          order is globals first then locals.

        - If one dict argument is passed, it is used for both globals and
          locals.

        - If two dict arguments are passed, they specify globals and
          locals, respectively.
        __no_type_check__Nrj   rt   FTr   c                 S     i | ]
\}}|t |qS r   r!   _strip_annotationsr,   ktr   r   r$   
<dictcomp>q      z"get_type_hints.<locals>.<dictcomp>__wrapped____globals__z- is not a module, class, method, or function.c                 S  r   r   r   r   r   r   r$   r     r   )rP   rJ   typeru   rv   rX   ri   rw   rh   rj   r'   r   rx   ry   rz   r   r   r!   r   
ModuleTyperF   r   _allowed_types	TypeError_get_defaultsOptional)re   rf   r   r   r|   r}   base_globalsr~   base_localsr   r:   nsobjdefaultsr   r   r$   get_type_hints"  sx   0



	





r   refr   c                 C  s   | j ||dS )N)rf   r   )	_evaluater   rf   r   r   r   r$   evaluate_fwd_ref  s   r   c                 C  s   | j ||t dS )N)rf   r   recursive_guard)r   	frozensetr   r   r   r$   r     s   _cls"TypeGuard[type[StandardDataclass]]c                 C  s
   t | S r    )dataclassesis_dataclass)r   r   r   r$   r     s   
r   rB   TypeGuard[TypeAliasType]c                 C  s
   t | tS r    )rJ   r   )rB   r   r   r$   origin_is_type_alias_type  r&   r   )r   r   r   r   )r0   r   r   r   )r0   r4   r   r   )r0   r4   r   r.   )r0   r4   r   r8   )r>   r   r   r   )rM   r   r   r   )r>   r4   r   r   )r]   r^   r   r_   r    )re   r   rf   r_   r   rg   )ro   r4   rp   r_   r   rg   )r:   r   rf   r_   r   r_   r   r   )r   r   r   r   r   r_   r   rg   )T)r   r   r   r   r   r   r   r   )NNF)
re   r   rf   r_   r   r_   r   r   r   rg   )NN)r   r   rf   r_   r   r_   r   r   )r   r4   r   r   )rB   r   r   r   )L__doc__
__future__r   Z_annotationsr   rX   r'   r!   collections.abcr   	functoolsr   r   r   r   r   Ztyping_extensionsr	   r
   r   r   r   r   r   _dataclassesr   r   ImportErrorr   Ztyping_baserY   ZTypingGenericAliasr   r   r   r%   ZWithArgsTypes_GenericAliasr(   r   r*   EllipsisEllipsisTyper+   rt   rF   addr/   ZTypeVarTyper2   r5   r6   r7   r9   rC   rG   NewTyper   rH   rL   rR   rV   rZ   r[   rd   rn   rs   r   r{   r   r   r   no_type_checkr   r   r   r   r   r   r$   <module>   s    $







 






	





*z
