o
    ?Hh6                     @  s  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	 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 d	dlmZ d	dl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l%m&Z& d	dl'm(Z( G dd deZ)dJddZ*e	dddKd d!Z+dLd)d*Z,dd+dMd4d5Z-dNd9d:Z.dOd>d?Z/ddd@dPdCdDZ0dQdFdGZ1dQdHdIZ2dS )RzmPrivate logic related to fields (the `Field()` function and `FieldInfo` class), and arguments to `Annotated`.    )annotationsN)copy)	lru_cache)TYPE_CHECKINGAny)PydanticUndefined)PydanticUserError   )_typing_extra)ConfigWrapper)extract_docstrings_from_cls)import_cached_base_modelimport_cached_field_info)Representation)get_cls_type_hints_lenientis_classvaris_finalvar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   Z/home/air/sanwanet/gpt-api/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   
	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   r+   r   r   r   r!   _PydanticGeneralMetadata7   s    r,   )annotated_typesr   r   )r   r,   r   r   r!   r$   2   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(   )use_attribute_docstringsr   itemsdescription)r.   r0   r2   fields_docsann_name
field_infor   r   r!   _update_fields_from_docstrings@   s   
r:   )typevars_maptype[BaseModel]basestuple[type[Any], ...]types_namespacedict[str, Any] | Noner;   dict[Any, Any] | None%tuple[dict[str, FieldInfo], set[str]]c                  s  t  }t }t| |}| jdi }i }	t }
| D ]G\ } dkr%q|jD ]L} |rt|D ]"}t	| rSt
||rB |jv sStd  dt|  d| dq1t fdd|jD }td  d	| j 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 ]9}dd t|rt|ndD }t	| r||u rq |v rq |vrqtd  d| j d|j dt qzt|  t}|tu rtW n= ty2    |v r||}n(i }| jddd D ]}| t|di  q |v r+t!|  }n||}Y nw t"|  |#||}zt$|   W n
 tyO   Y nw | jd } |j%v r_t&d||	 < q|ru|	' D ]	}|(|| qkt)| |	| |	|
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.
    __annotations__model_configzField "z" conflicts with member z of protected namespace "z".c                 3  s    | ]
}  |s|V  qd S r(   
startswith).0xr8   r   r!   	<genexpr>   s    

z'collect_model_fields.<locals>.<genexpr>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)rG   fieldr   r   r!   	<setcomp>   s    z'collect_model_fields.<locals>.<setcomp>r   zField name "z" in "z"" shadows an attribute in parent ""Nmodel_fields__pydantic_decorators__z0you can't override a field with a computed field)*r   r   r   r)   getsetr5   protected_namespacesrF   hasattr
issubclassrT   	NameErrorgetattrtuplewarningswarnr   UserWarningr   add_is_finalvar_with_default_valr   is_valid_field_name__pydantic_root_model__dataclassesis_dataclassr0   r   AttributeErrorfrom_annotation	__bases__updater   #_warn_on_nested_alias_in_annotationfrom_annotated_attributedelattrcomputed_fields
ValueErrorvaluesapply_typevars_mapr:   )r.   r=   r2   r?   r;   r   
FieldInfo_
type_hintsr   r0   
class_varsann_typeprotected_namespacebvalid_namespacesgeneric_originbasedataclass_fieldsdefaultr9   model_fields_lookuprH   
decoratorsrP   r   rI   r!   collect_model_fieldsH   s   













r   ru   r8   strc                 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   r\   r
   is_annotatedget_args
isinstancealiasr^   r_   r`   )ru   r8   r   argsanno_arganno_type_argr   r   r!   rk      s   

rk   type_valboolc                 C  sD   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   r   r   r|   default_factory)r   r   r   r   r   r!   rb      s   rb   )r;   r2   type[StandardDataclass]ConfigWrapper | Nonec                C  sJ  t  }i }| j}tt| }tj| j}|dur"i |j|p i }|	 D ]c\}	}
t
|
j||}t|r7q&|
jsG|
jtjkrG|
jtjkrGq&t|
j|rj|
jjrb|
jjdu ratd|	 dddq&|||
j}n|||
}|||	< |jturtt| |	||rt| |	|j q&|r| D ]}||| q|durt| || |S )aF  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.
        config_wrapper: The config wrapper instance.

    Returns:
        The dataclass fields.
    NFzDataclass field zD has init=False and init_var=True, but these are mutually exclusive.zclashing-init-and-init-var)code)r   __dataclass_fields__dictvarssysmodulesrV   r   r)   r5   r
   eval_type_lenienttyper   initr|   re   MISSINGr   r   init_varr   rl   r   r\   setattrrp   rq   r:   )r.   r?   r;   r2   rr   r0   r{   cls_localnssource_moduler8   dataclass_fieldru   r9   rP   r   r   r!   collect_dataclass_fields   sH   
r   rO   c                 C  s   |  d S )N_rE   rN   r   r   r!   rc   H  s   rc   c                 C  s   |  do
|  d S )Nr   __rE   rN   r   r   r!   is_valid_privateattr_nameL  s   r   )r"   r   r#   r   )r#   r'   )r.   r/   r0   r1   r2   r   r#   r3   )r.   r<   r=   r>   r2   r   r?   r@   r;   rA   r#   rB   )ru   r/   r8   r   r#   r3   )r   r/   r   r   r#   r   )
r.   r   r?   r@   r;   rA   r2   r   r#   r1   )rO   r   r#   r   )3r   
__future__r   _annotationsre   r   r^   r   	functoolsr   typingr   r   pydantic_corer   pydantic.errorsr    r
   _configr   _docs_extractionr   _import_utilsr   r   _reprr   r   r   r   r-   r   r0   r   mainr   _dataclassesr   _decoratorsr   r   r%   r$   r:   r   rk   rb   r   rc   r   r   r   r   r!   <module>   sJ    

 


H