o
    "chZ                     @  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:m;Z; ddl<m=Z= G dd de0Z>dZd$d%Z?e
d[d'd(Z@d\d]d1d2ZAdd3d^d<d=ZBd_dAdBZCd`dEdFZDddddGdadKdLZEdbdNdOZFdcdQdRZGdcdSdTZHdddXdYZIdS )ezmPrivate 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)PydanticDataclass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(   X/home/air/goalskill/back/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   
	r2   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,   r6   r(   r(   r(   r.   _PydanticGeneralMetadata>   s    r7   )annotated_typesr    r'   )r    r7   r(   r(   r.   r1   9   s   r1   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)r9   r;   r=   fields_docsann_name
field_infor(   r(   r.   _update_fields_from_docstringsG   s   
rF   )typevars_maptype[BaseModel]config_wrapperr   ns_resolverNsResolver | NonerG   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)rJ   __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_hintsr4   getsetrA   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_docstringsrF   )r9   rI   rJ   rG   r#   
FieldInfo_basesparent_fields_lookupbasemodel_fields
type_hintsr   r;   
class_varsrD   ann_type	evaluatedprotected_namespacens_violationbvalid_namespacespnassigned_valuegeneric_origindataclass_fieldsrE   original_assignment
decoratorsrX   r(   r(   r.   collect_model_fieldsN   s   























r   r   rD   rl   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   rd   r   is_annotatedr   r   get_argsrj   aliasrr   rs   rt   )r   rD   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.
    r[   N)r   pushrN   rA   r}   rB   r   	eval_typer~   types_namespacer   replace_typesr   r   r{   r   r|   r   )r9   rJ   rG   r   rebuilt_fieldsf_namerE   existing_descannassign	new_fieldr(   r(   r.   rebuild_model_fields-  s.   


r   )rJ   rG   rI   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}|	j|_n|j||	tjd}|	|_|sd|_||_|||< |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.
    rO   FzDataclass field zD has init=False and init_var=True, but these are mutually exclusive.zclashing-init-and-init-var)coder[   N__is_pydantic_dataclass__r@   )%r   r   __dataclass_fields__rc   __mro__ry   rz   r   rA   r4   rg   r   r   try_eval_typetyperu   initr   MISSINGdefault_factoryrj   init_varr   r   r   	DATACLASSr   r}   r~   r   rd   setattrr   r   r   rF   rn   )r9   rJ   rG   rI   r   r;   r   r   rD   dataclass_fieldglobalnslocalnsr   r   rE   rX   r(   r(   r.   collect_dataclass_fieldsX  st   






6
r   type[PydanticDataclass]c                C  s   t  }i }|| H | j D ]9\}}|jr|||< q|j}tj|jg|j	R  }	t
|	|}	|j|	|jtjd}
|
jdurB|
jn||
_|
||< qW d   |S 1 sUw   Y  |S )a  Rebuild the (already present) dataclass fields by trying to reevaluate annotations.

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

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

    Note:
        This function *doesn't* mutate the dataclass fields in place, as it can be called during
        schema generation, where you don't want to mutate other dataclass's fields.
    r[   N)r   r   rN   rA   r}   rB   r   r   r~   r   r   r   r   r   r   r   )r9   rI   rJ   rG   r   r   r   rE   r   r   r   r(   r(   r.   rebuild_dataclass_fields  s2   


r   rV   c                 C  s   |  d S )N_rm   rU   r(   r(   r.   rw     s   rw   c                 C  s   |  do
|  d S )Nr   __r   rU   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   r0   r    )r0   r3   )F)r9   r:   r;   r<   r=   r>   r0   r?   )
r9   rH   rI   r   rJ   rK   rG   rL   r0   rM   )r   r:   rD   rl   r0   r?   )r9   rH   rJ   r   rG   r   r0   r<   )
r9   r   rJ   rK   rG   r   rI   r   r0   r<   )
r9   r   rI   r   rJ   r   rG   r   r0   r<   )rV   rl   r0   r>   )r   r   r0   r   )Jr,   
__future__r   _annotationsry   rr   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   r8   r    r;   r"   mainr#   _dataclassesr$   r%   _decoratorsr&   r'   r2   r1   rF   r   r   r   r   r   rw   r   r   r(   r(   r(   r.   <module>   s^    
 
P
.
i
-
