o
    ~j6hQ                     @  s  d Z ddlm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 dd	lmZmZmZm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$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 erddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z< G dd de0Z=dWd$d%Z>e
dXd'd(Z?dYdZd1d2Z@dd3d[d<d=ZAd\dAdBZBd]dEdFZCddddGd^dKdLZDd_dNdOZEd_dPdQZFd`dUdVZGdS )azmPrivate logic related to fields (the `Field()` function and `FieldInfo` class), and arguments to `Annotated`.    )annotationsN)Mapping)copy)cache)	Parameterismethoddescriptor	signature)Pattern)TYPE_CHECKINGAnyCallableTypeVar)PydanticUndefined)TypeIs
get_origin)typing_objects)AnnotationSource)PydanticDeprecatedSince211)PydanticUserError   )	_generics_typing_extra)ConfigWrapper)extract_docstrings_from_cls)import_cached_base_modelimport_cached_field_info)
NsResolver)Representation)can_be_positionalBaseMetadata   )	FieldInfo)	BaseModel)StandardDataclass)DecoratorInfosc                   @  s   e Zd ZdZdZdS )PydanticMetadataz0Base class for annotation markers like `Strict`. N)__name__
__module____qualname____doc__	__slots__r'   r'   r'   i/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/site-packages/pydantic/_internal/_fields.pyr&   '   s    r&   metadatar   returnr    c                  K  s
   t  | S )zCreate a new `_PydanticGeneralMetadata` class with the given metadata.

    Args:
        **metadata: The metadata to add.

    Returns:
        The new `_PydanticGeneralMetadata` class.
    )_general_metadata_cls)r.   r'   r'   r-   pydantic_general_metadata-   s   
	r1   type[BaseMetadata]c                  C  s"   ddl m}  G dd dt| }|S )zCDo it this way to avoid importing `annotated_types` at import time.r   r   c                   @  s   e Zd ZdZdddZdS )z7_general_metadata_cls.<locals>._PydanticGeneralMetadataz,Pydantic general metadata like `max_digits`.r.   r   c                 S  s
   || _ d S )N)__dict__)selfr.   r'   r'   r-   __init__A   s   
z@_general_metadata_cls.<locals>._PydanticGeneralMetadata.__init__N)r.   r   )r(   r)   r*   r+   r5   r'   r'   r'   r-   _PydanticGeneralMetadata>   s    r6   )annotated_typesr    r&   )r    r6   r'   r'   r-   r0   9   s   r0   Fcls	type[Any]fieldsdict[str, FieldInfo]use_inspectboolNonec                 C  s>   t | |d}| D ]\}}|jd u r||v r|| |_q
d S )Nr<   )r   itemsdescription)r8   r:   r<   fields_docsann_name
field_infor'   r'   r-   _update_fields_from_docstringsG   s   
rE   )typevars_maptype[BaseModel]config_wrapperr   ns_resolverNsResolver | NonerF   Mapping[TypeVar, Any] | None%tuple[dict[str, FieldInfo], set[str]]c                C  s  t  }t }| j}i }t|D ]}t|dd }	r||	 qtj| |d}
| j	di }i }t
 }|
 D ]\}\}}|dkrBq6|jD ]}d}t|trV||du}n
t|tr`||}|r|D ]%}t||rt||rx|t|di v std| dt|| d	| d
qdd}|jD ]!}t|tr||s|d|j df7 }q||s||f7 }qtd| d| j d| d| d	t qEt|r|| q6t| |t}t|sq6| jr|dkrtd|dt| di 	d}|D ]>}dd t |rt!|ndD }t||r4||u rq||v rq||vr"qtd| d| j" d|j" dt q|tu r]||v sD||vrV|j#|t$j%d}|sUd|_&||_'nzt(|| }nst)|| t||rvt*|j+rv|j+,d| |_+|st||r|- n|}|j.||t$j%d}|sd|_&||_'||_/n#d|j0v r|1 stjd|d |d!|d"t2d#d$ || q6zt3| | W n
 t4y   Y nw | jd% }||j5v rt6d&|d'| jd(|||< q6|r |7 D ]}|j&r|8| q|j9r	t:| | ||fS ))a*  Collect the fields and class variables names of a nascent Pydantic model.

    The fields collection process is *lenient*, meaning it won't error if string annotations
    fail to evaluate. If this happens, the original annotation (and assigned value, if any)
    is stored on the created `FieldInfo` instance.

    The `rebuild_model_fields()` should be called at a later point (e.g. when rebuilding the model),
    and will make use of these stored attributes.

    Args:
        cls: BaseModel or dataclass.
        config_wrapper: The config wrapper instance.
        ns_resolver: Namespace resolver to use when getting model annotations.
        typevars_map: A dictionary mapping type variables to their concrete types.

    Returns:
        A two-tuple containing model fields and class variables names.

    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.
    __pydantic_fields__N)rI   __annotations__model_configFzField "z" conflicts with member z of protected namespace "z".r'   zre.compile()z" in 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`__pydantic_generic_metadata__originc                 S  s   h | ]}|j qS r'   name).0fieldr'   r'   r-   	<setcomp>   s    z'collect_model_fields.<locals>.<setcomp>zField name "z" in "z"" shadows an attribute in parent ""_sourcefinalzAnnotation z= is marked as final and has a default value. Pydantic treats zz as a class variable, but it will be considered as a normal field in V3 to be aligned with dataclasses. If you still want zV to be considered as a class variable, annotate it as: `ClassVar[<type>] = <default>.`   )category
stacklevel__pydantic_decorators__zField z
 of class zf overrides symbol of same name in a parent class. This override with a computed_field is incompatible.);r   r   	__bases__reversedgetattrupdater   get_model_type_hintsr3   getsetr@   protected_namespaces
isinstancer	   matchstr
startswithhasattr
issubclass	NameErrorpatternwarningswarnr(   UserWarningis_classvar_annotationaddr   is_valid_field_name__pydantic_root_model__dataclassesis_dataclassr:   r*   from_annotationr   CLASS	_complete_original_annotationr   #_warn_on_nested_alias_in_annotationr   default__get___copyfrom_annotated_attribute_original_assignment_qualifiersis_requiredr   delattrAttributeErrorcomputed_fields	TypeErrorvaluesapply_typevars_mapuse_attribute_docstringsrE   )r8   rH   rI   rF   r#   
FieldInfo_basesparent_fields_lookupbasemodel_fields
type_hintsr   r:   
class_varsrC   ann_type	evaluatedprotected_namespacens_violationbvalid_namespacespnassigned_valuegeneric_origindataclass_fieldsrD   original_assignment
decoratorsrW   r'   r'   r-   collect_model_fieldsN   s   























r   r   rC   rk   c                 C  sv   t  }t| dd }|r7|D ]+}tt|r6t|D ]}t||r5|jd ur5t	
d| dt   d S qqd S d S )N__args__z `alias` specification on field "z5" must be set on outermost annotation to take effect.)r   rc   r   is_annotatedr   r   get_argsri   aliasrq   rr   rs   )r   rC   r"   argsanno_arganno_type_argr'   r'   r-   r~     s   
r~   r   Mapping[TypeVar, Any]c                C  s   t  }i }|| W | j D ]H\}}|jr|||< q|j}tj|jg|j	R  }t
||}|j }	tu r@|j|tjd}
n	|j||	tjd}
|
jdurQ|
jn||
_|
||< qW d   |S 1 sdw   Y  |S )a  Rebuild the (already present) model fields by trying to reevaluate annotations.

    This function should be called whenever a model with incomplete fields is encountered.

    Raises:
        NameError: If one of the annotations failed to evaluate.

    Note:
        This function *doesn't* mutate the model fields in place, as it can be called during
        schema generation, where you don't want to mutate other model's fields.
    rZ   N)r   pushrM   r@   r|   rA   r   	eval_typer}   types_namespacer   replace_typesr   r   rz   r   r{   r   )r8   rI   rF   r   rebuilt_fieldsf_namerD   existing_descannassign	new_fieldr'   r'   r-   rebuild_model_fields,  s.   


r   )rI   rF   rH   type[StandardDataclass]dict[Any, Any] | NoneConfigWrapper | Nonec             	   C  s  t  }i }|p	t }| j}t| jD ]}t|sq|| | D ]{\}}	||j	
di vr2q$|j\}
}t|	j|
|\}}t|rGq$|	jsW|	jtju rW|	jtju rWq$t|	j|r}|	jjrr|	jjdu rqtd| dddq$|j||	jtjd}n	|j||	tjd}|||< |jturtt| |||rt| ||j q$W d   n1 sw   Y  q|r| D ]}|| q|dur|jrt | |t!| d	 d
 |S )a|  Collect the fields of a dataclass.

    Args:
        cls: dataclass.
        ns_resolver: Namespace resolver to use when getting dataclass annotations.
            Defaults to an empty instance.
        typevars_map: A dictionary mapping type variables to their concrete types.
        config_wrapper: The config wrapper instance.

    Returns:
        The dataclass fields.
    rN   FzDataclass field zD has init=False and init_var=True, but these are mutually exclusive.zclashing-init-and-init-var)coderZ   N__is_pydantic_dataclass__r?   )"r   r   __dataclass_fields__rb   __mro__rx   ry   r   r@   r3   rf   r   r   try_eval_typetypert   initr   MISSINGdefault_factoryri   init_varr   r   r   	DATACLASSr   rc   setattrr   r   r   rE   rm   )r8   rI   rF   rH   r   r:   r   r   rC   dataclass_fieldglobalnslocalnsr   _rD   rW   r'   r'   r-   collect_dataclass_fieldsW  sj   





0
r   rU   c                 C  s   |  d S )Nr   rl   rT   r'   r'   r-   rv     s   rv   c                 C  s   |  do
|  d S )Nr   __r   rT   r'   r'   r-   is_valid_privateattr_name  s   r   r   3Callable[[], Any] | Callable[[dict[str, Any]], Any]'TypeIs[Callable[[dict[str, Any]], Any]]c              	   C  s\   zt | }W n ttfy   Y dS w t|j }t|dko-t|d o-|d jt	j
u S )zMWhether the provided default factory callable has a validated data parameter.Fr   r   )r   
ValueErrorr   list
parametersr   lenr   r   r   empty)r   sigr   r'   r'   r-   takes_validated_data_argument  s   (r   )r.   r   r/   r    )r/   r2   )F)r8   r9   r:   r;   r<   r=   r/   r>   )
r8   rG   rH   r   rI   rJ   rF   rK   r/   rL   )r   r9   rC   rk   r/   r>   )r8   rG   rI   r   rF   r   r/   r;   )
r8   r   rI   rJ   rF   r   rH   r   r/   r;   )rU   rk   r/   r=   )r   r   r/   r   )Hr+   
__future__r   _annotationsrx   rq   collections.abcr   r   	functoolsr   inspectr   r   r   rer	   typingr
   r   r   r   pydantic_corer   typing_extensionsr   r   typing_inspectionr   typing_inspection.introspectionr   pydanticr   pydantic.errorsr    r   r   _configr   _docs_extractionr   _import_utilsr   r   _namespace_utilsr   _reprr   _utilsr   r7   r    r:   r"   mainr#   _dataclassesr$   _decoratorsr%   r&   r1   r0   rE   r   r~   r   r   rv   r   r   r'   r'   r'   r-   <module>   s\    
 
O
.
c
