o
    ZhP                     @  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'   Q/var/www/html/lang_env/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<   Zfields_docsann_name
field_infor'   r'   r-   _update_fields_from_docstringsG   s   
rD   )typevars_maptype[BaseModel]config_wrapperr   ns_resolverNsResolver | NonerE   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 rf||v rH|j#|t$j%d}n||v rTt&|| }n|j#|t$j%d}|sed|_'||_(nst)|| t||rt*|j+r|j+,d| |_+|st||rt&|n|}|j-||t$j%d}|sd|_'||_(||_.n#d|j/v r|0 stjd|d |d!|d"t1d#d$ || q6zt2| | W n
 t3y   Y nw | jd% }||j4v rt5d&|d'| jd(|||< q6|r	|6 D ]}|j'r|7| q|j8rt9| | ||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)rH   __annotations__Z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`Z__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
stacklevelZ__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   Zget_model_type_hintsr3   getsetr@   Zprotected_namespaces
isinstancer	   matchstr
startswithhasattr
issubclass	NameErrorpatternwarningswarnr(   UserWarningis_classvar_annotationaddr   is_valid_field_nameZ__pydantic_root_model__dataclassesis_dataclassr:   r*   from_annotationr   CLASSr   	_complete_original_annotation#_warn_on_nested_alias_in_annotationr   default__get__from_annotated_attribute_original_assignmentZ_qualifiersZis_requiredr   delattrAttributeErrorZcomputed_fields	TypeErrorvaluesapply_typevars_mapuse_attribute_docstringsrD   )r8   rG   rH   rE   r#   
FieldInfo_basesZparent_fields_lookupbaseZmodel_fieldsZ
type_hintsr   r:   Z
class_varsrB   ann_typeZ	evaluatedZprotected_namespaceZns_violationbZvalid_namespacesZpnZassigned_valueZgeneric_origindataclass_fieldsrC   Zoriginal_assignmentZ
decoratorsrT   r'   r'   r-   collect_model_fieldsN   s   

























r   r   rB   re   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   r_   r   Zis_annotatedr   r   get_argsrc   aliasrk   rl   rm   )r   rB   r"   argsZanno_argZanno_type_argr'   r'   r-   rw     s   
rw   r   Mapping[TypeVar, Any]c          	      C  s   t  }i }|| I | j D ]:\}}|jr|||< qtj|jg|jR  }t	
||}|j }tu r?|j|tjd||< q|j||tjd||< qW d   |S 1 sVw   Y  |S )ah  Rebuild the (already present) model fields by trying to reevaluate annotations.

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

    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.
    rW   N)r   pushrL   r@   ru   r   Z	eval_typerv   types_namespacer   Zreplace_typesr{   r   rs   r   rt   rz   )	r8   rH   rE   r   Zrebuilt_fieldsf_namerC   annZassignr'   r'   r-   rebuild_model_fields-  s,   

r   )rH   rE   rG   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.
    rM   FzDataclass field zD has init=False and init_var=True, but these are mutually exclusive.zclashing-init-and-init-var)coderW   NZ__is_pydantic_dataclass__r?   )"r   r   __dataclass_fields__r^   __mro__rq   rr   r   r@   r3   ra   r   r   Ztry_eval_typetypern   initrx   MISSINGdefault_factoryrc   Zinit_varr   rz   r   Z	DATACLASSr   r_   setattrr   r   r   rD   rg   )r8   rH   rE   rG   r   r:   r   r   rB   Zdataclass_fieldglobalnslocalnsr   _rC   rT   r'   r'   r-   collect_dataclass_fieldsS  sj   





0
r   rR   c                 C  s   |  d S )Nr   rf   rQ   r'   r'   r-   rp     s   rp   c                 C  s   |  do
|  d S )Nr   __r   rQ   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   rx   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   rF   rG   r   rH   rI   rE   rJ   r/   rK   )r   r9   rB   re   r/   r>   )r8   rF   rH   r   rE   r   r/   r;   )
r8   r   rH   rI   rE   r   rG   r   r/   r;   )rR   re   r/   r=   )r   r   r/   r   )Hr+   
__future__r   Z_annotationsrq   rk   collections.abcr   r   	functoolsr   inspectr   r   r   rer	   typingr
   r   r   r   Zpydantic_corer   typing_extensionsr   r   Ztyping_inspectionr   Ztyping_inspection.introspectionr   Zpydanticr   Zpydantic.errorsr    r   r   _configr   Z_docs_extractionr   Z_import_utilsr   r   Z_namespace_utilsr   _reprr   Z_utilsr   r7   r    r:   r"   mainr#   Z_dataclassesr$   Z_decoratorsr%   r&   r1   r0   rD   r   rw   r   r   rp   r   r   r'   r'   r'   r-   <module>   s\    
 
P
)
c
