o
    .ѹgB                     @  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
mZmZ ddlmZmZ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 ddlmZm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& erddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 G dd de$Z1dRdd Z2edd!dSd#d$Z3dTd,d-Z4dd.dUd7d8Z5dVd<d=Z6dWdAdBZ7ddddCdXdFdGZ8dYdIdJZ9dYdKdLZ:dZdPdQZ;dS )[zmPrivate logic related to fields (the `Field()` function and `FieldInfo` class), and arguments to `Annotated`.    )annotationsN)copy)	lru_cache)	Parameterismethoddescriptor	signature)TYPE_CHECKINGAnyCallablePattern)PydanticUndefined)TypeIs)PydanticUserError   )_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    ^/Users/admin/.pyenv/versions/3.10.0/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.
    N)_general_metadata_cls)r'   r    r    r&   pydantic_general_metadata(   s   
	r*   )maxsize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__<   s   
z@_general_metadata_cls.<locals>._PydanticGeneralMetadata.__init__N)r'   r	   )r!   r"   r#   r$   r0   r    r    r    r&   _PydanticGeneralMetadata9   s    r1   N)annotated_typesr   r   )r   r1   r    r    r&   r)   4   s   r)   cls	type[Any]fieldsdict[str, FieldInfo]config_wrapperr   Nonec                 C  sD   |j rt| }| D ]\}}|jd u r||v r|| |_qd S d S r-   )Zuse_attribute_docstringsr   itemsdescription)r3   r5   r7   Zfields_docsann_name
field_infor    r    r&   _update_fields_from_docstringsB   s   
r=   )typevars_maptype[BaseModel]basestuple[type[Any], ...]ns_resolverNsResolver | Noner>   dict[Any, Any] | None%tuple[dict[str, FieldInfo], set[str]]c                C  s  t  }t }i }t|D ]}t|dd }	r||	 qtj| |d}
| jdi }i }t	 }|

 D ]\}\}}|dkr?q3|jD ]}d}t|trS||du}n
t|tr]||}|r|D ]%}t||rt||ru|t|di v std| dt|| d	| d
qad}|jD ]!}t|tr||s|d|j df7 }q||s||f7 }qtd| d| j d| d| d	t qBt|r|| q3t|t| |tr|| q3t|sq3| jr|dkrtd|dt| di d}|D ]>}dd t |rt!|ndD }t||r:||u rq||v r"q||vr(qtd| d| j" d|j" dt qzt| |t}|tu rIt#W n, t#yv   ||v r`|$|}||_%n||v rlt&|| }n|$|}||_%Y n5w t'|| t||rt(|j)r|j)*d| |_)|+||}||_%zt,| | W n
 t#y   Y nw | jd }||j-v rt.d|||< q3|r|/ D ]}|0| qt1| || ||fS )ab  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.
        ns_resolver: Namespace resolver to use when getting model annotations.
        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.
    Z__pydantic_fields__N)rB   __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 ""Z__pydantic_decorators__z0you can't override a field with a computed field)2r   r   reversedgetattrupdater   Zget_model_type_hintsr.   getsetr9   Zprotected_namespaces
isinstancer   matchstr
startswithhasattr
issubclass	NameErrorpatternwarningswarnr!   UserWarningis_classvar_annotationadd_is_finalvar_with_default_valr   is_valid_field_nameZ__pydantic_root_model__dataclassesis_dataclassr5   r#   AttributeErrorZfrom_annotation	evaluatedr   #_warn_on_nested_alias_in_annotationr   default__get__from_annotated_attributedelattrZcomputed_fields
ValueErrorvaluesapply_typevars_mapr=   )r3   r@   r7   rB   r>   r   
FieldInfo_Zparent_fields_lookupbaseZmodel_fieldsZ
type_hintsr   r5   Z
class_varsr;   ann_typerg   Zprotected_namespaceZns_violationbZvalid_namespacesZpnZgeneric_origindataclass_fieldsri   r<   Z
decoratorsrM   r    r    r&   collect_model_fieldsJ   s   

























ru   rr   r;   rW   c                 C  sr   t  }t| dd }|r5|D ])}t|r4t|D ]}t||r3|jd ur3t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   rQ   r   Zis_annotatedget_argsrU   aliasr]   r^   r_   )rr   r;   r   argsZanno_argZanno_type_argr    r    r&   rh      s   

rh   type_valboolc                 C  sF   t  }t| s
dS |tu rdS t||r!|jtu r!|jd u r!dS dS )NFT)r   r   Zis_finalvarr   rU   ri   default_factory)rz   r{   r   r    r    r&   rb     s   
rb   )rB   r>   r7   type[StandardDataclass]ConfigWrapper | Nonec             	   C  s  t  }i }|p	t }| j}t| jD ]}t|sq|| | D ]u\}}	||j	
di vr2q$|j\}
}t|	j|
|\}}t|rGq$|	jsW|	jtju rW|	jtju rWq$t|	j|rz|	jjrr|	jjdu rqtd| dddq$|||	j}n|||	}|||< |jturtt| |||rt| ||j q$W d   q1 sw   Y  q|r| D ]}|| q|durt| || |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.
    rF   FzDataclass field zD has init=False and init_var=True, but these are mutually exclusive.zclashing-init-and-init-var)codeN)r   r   __dataclass_fields__rP   __mro__rd   re   pushr9   r.   rS   Ztypes_namespacer   Ztry_eval_typetyper`   initri   MISSINGr}   rU   Zinit_varr   rk   r   rQ   setattrrn   ro   r=   )r3   rB   r>   r7   rp   r5   rt   rq   r;   Zdataclass_fieldglobalnslocalnsrr   _r<   rM   r    r    r&   collect_dataclass_fields  s\   






,r   rK   c                 C  s   |  d S )Nr   rX   rJ   r    r    r&   rc   s  s   rc   c                 C  s   |  do
|  d S )Nr   __r   rJ   r    r    r&   is_valid_privateattr_namew  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   N)r   rm   	TypeErrorlist
parametersrn   lenr   ri   r   empty)r}   sigr   r    r    r&   takes_validated_data_argument{  s   (r   )r'   r	   r(   r   )r(   r,   )r3   r4   r5   r6   r7   r   r(   r8   )r3   r?   r@   rA   r7   r   rB   rC   r>   rD   r(   rE   )rr   r4   r;   rW   r(   r8   )rz   r4   r{   r	   r(   r|   )
r3   r~   rB   rC   r>   rD   r7   r   r(   r6   )rK   rW   r(   r|   )r}   r   r(   r   )<r$   
__future__r   Z_annotationsrd   r]   r   	functoolsr   inspectr   r   r   typingr   r	   r
   r   Zpydantic_corer   Ztyping_extensionsr   Zpydantic.errorsr    r   _configr   Z_docs_extractionr   Z_import_utilsr   r   Z_namespace_utilsr   _reprr   _utilsr   r2   r   r5   r   mainr   _dataclassesr   Z_decoratorsr   r   r*   r)   r=   ru   rh   rb   r   rc   r   r   r    r    r    r&   <module>   sR    

 
4

Y
