o
    $6dC+                     @  s4  d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZ ddlm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mZ e	r`ddlmZ ddlmZ ddlmZ 		d<d=ddZG dd deZ G dd de eZ!dd d>d+d,Z"d?d0d1Z#dd d@d4d5Z$dAd8d9Z%dAd:d;Z&dS )BzmPrivate logic related to fields (the `Field()` function and `FieldInfo` class), and arguments to `Annotated`.    )annotationsN)copy)TYPE_CHECKINGAny)BaseMetadata)PydanticUndefined   )_typing_extra)ConfigWrapper)Representation)get_cls_type_hints_lenientget_type_hintsis_classvaris_finalvar   	FieldInfo	BaseModel)StandardDataclassFobjr   localnsdict[str, Any] | Noneinclude_extrasboolreturndict[str, Any]c                 C  sH   t | dd}d}|rztj| j}W n	 ty   Y nw t| |||dS )a  Gets type hints for an object by inferring the global namespace.

    It uses the `typing.get_type_hints`, The only thing that we do here is fetching
    global namespace from `obj.__module__` if it is not `None`.

    Args:
        obj: The object to get its type hints.
        localns: The local namespaces.
        include_extras: Whether to recursively include annotation metadata.

    Returns:
        The object type hints.
    
__module__N)globalnsr   r   )getattrsysmodules__dict__KeyErrorr   )r   r   r   module_namer    r%   qC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\pydantic/_internal/_fields.pyget_type_hints_infer_globalns   s   r'   c                   @  s   e Zd ZdZdZdS )PydanticMetadataz0Base class for annotation markers like `Strict`.r%   N)__name__r   __qualname____doc__	__slots__r%   r%   r%   r&   r(   5   s    r(   c                   @  s   e Zd ZdZdddZdS )PydanticGeneralMetadataz*Pydantic general metada like `max_digits`.metadatar   c                 K  s
   || _ d S N)r"   )selfr.   r%   r%   r&   __init__>   s   
z PydanticGeneralMetadata.__init__N)r.   r   )r)   r   r*   r+   r1   r%   r%   r%   r&   r-   ;   s    r-   )typevars_mapclstype[BaseModel]basestuple[type[Any], ...]config_wrapperr
   types_namespacer2   dict[Any, Any] | None%tuple[dict[str, FieldInfo], set[str]]c                  s  ddl m} t| |}| jdi }i }t }	| D ]\ }
 dkr%q|jD ]N} |rv|D ](}t	| rYddl
m} t||rH |jv sYtd  dt|  d| d	q1t fd
d|jD }td  d| d| dt q(t|
r|	  qt|
t|  tr|	  qt sq| jr dkrtd dt| di d}|D ]}t	| r||u rqtd  d|j dt qzt|  t}|tu rtW n; ty    |v r||
}n'i }| jddd D ]}|t|di  q |v rt|  }n||
}Y nw | |
|}zt!|   W n
 ty+   Y nw || < q|rB|" D ]	}|#|| q8||	fS )a[  Collect the fields of a nascent pydantic model.

    Also collect the names of any ClassVars present in the type hints.

    The returned value is a tuple of two items: the fields dict, and the set of ClassVar names.

    Args:
        cls: BaseModel or dataclass.
        bases: Parents of the class, generally `cls.__bases__`.
        config_wrapper: The config wrapper instance.
        types_namespace: Optional extra namespace to look for types in.
        typevars_map: A dictionary mapping type variables to their concrete types.

    Returns:
        A tuple contains fields and class variables.

    Raises:
        NameError:
            - If there is a conflict between a field name and protected namespaces.
            - If there is a field other than `root` in `RootModel`.
            - If a field shadows an attribute in the parent model.
    r   r   __annotations__Zmodel_configr   zField "z" conflicts with member z of protected namespace "z".c                 3  s    | ]
}  |s|V  qd S r/   
startswith).0xann_namer%   r&   	<genexpr>|   s    

z'collect_model_fields.<locals>.<genexpr>z)" has conflict with protected namespace "z_".

You may be able to resolve this warning by setting `model_config['protected_namespaces'] = z`.rootzUnexpected field with name z4; only 'root' is allowed as a field of a `RootModel`Z__pydantic_generic_metadata__originzField name "z"" shadows an attribute in parent "z"; Nmodel_fields)$fieldsr   r   r"   getsetitemsZprotected_namespacesr=   hasattrmainr   
issubclassrF   	NameErrorr   tuplewarningswarnUserWarningr   add_is_finalvar_with_default_valr   is_valid_field_nameZ__pydantic_root_model__r*   AttributeErrorZfrom_annotation	__bases__updater   from_annotated_attributedelattrvaluesapply_typevars_map)r3   r5   r7   r8   r2   r   Z
type_hintsr   rG   Z
class_varsann_typeZprotected_namespacebr   Zvalid_namespacesZgeneric_originbasedefault
field_infoZmodel_fields_lookupr?   fieldr%   r@   r&   collect_model_fieldsB   s   










rc   type_	type[Any]valc                 C  sJ   ddl m} t| sdS |tu rdS t||r#|jtu r#|jd u r#dS dS )Nr   r   FT)rG   r   r   r   
isinstancer`   default_factory)rd   rf   r   r%   r%   r&   rT      s   rT   type[StandardDataclass]dict[str, FieldInfo]c                C  s   ddl m} i }| j}tt| }| D ]M\}}t|j||}	t	|	r&q|j
s0|jtjkr0qt|j|rC|jjr;q||	|j}
n||	|}
|
||< |
jturbtt| ||
|rbt| ||
j q|rr| D ]}||| qi|S )a  Collect the fields of a dataclass.

    Args:
        cls: dataclass.
        types_namespace: Optional extra namespace to look for types in.
        typevars_map: A dictionary mapping type variables to their concrete types.

    Returns:
        The dataclass fields.
    r   r   )rG   r   __dataclass_fields__dictvarsrJ   r	   Zeval_type_lenienttyper   initrh   dataclassesMISSINGrg   r`   Zinit_varrY   r   r   setattrr[   r\   )r3   r8   r2   r   rG   Zdataclass_fieldsZcls_localnsrA   Zdataclass_fieldr]   ra   rb   r%   r%   r&   collect_dataclass_fields   s.   rs   namestrc                 C  s   |  d S )N_r<   rt   r%   r%   r&   rU     s   rU   c                 C  s   |  do
|  d S )Nrv   __r<   rw   r%   r%   r&   is_valid_privateattr_name
  s   ry   )NF)r   r   r   r   r   r   r   r   )r3   r4   r5   r6   r7   r
   r8   r   r2   r9   r   r:   )rd   re   rf   r   r   r   )r3   ri   r8   r   r2   r9   r   rj   )rt   ru   r   r   )'r+   
__future__r   Z_annotationsrp   r    rP   r   typingr   r   Zannotated_typesr   Zpydantic_corer    r	   _configr
   _reprr   r   r   r   r   rG   r   rL   r   _dataclassesr   r'   r(   r-   rc   rT   rs   rU   ry   r%   r%   r%   r&   <module>   s<     

1