a
    OfV:                     @  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 d	dlmZmZmZ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%m&Z& dIdddddddZ'G dd deZ(ddd d!d"Z)e	dd#d$d%d&d'Z*d(d)d*d+d,d-d.Z+dd/d0d1d*dd2d3d4d5d6Z,d(d7d8d9d:Z-d(ddd;d<d=Z.ddd>d?dd2d@d)dAdBdCZ/d7ddDdEdFZ0d7ddDdGdHZ1dS )JzmPrivate 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)Representation)get_cls_type_hints_lenientget_type_hintsis_classvaris_finalvarBaseMetadata   	FieldInfo	BaseModel)StandardDataclass)DecoratorInfosFr   zdict[str, Any] | Noneboolzdict[str, Any])objlocalnsinclude_extrasreturnc                 C  sH   t | dd}d}|r8ztj| j}W n ty6   Y n0 t| |||dS )a  Gets type hints for an object by inferring the global namespace.

    It uses the `typing.get_type_hints`, The only thing that we do here is fetching
    global namespace from `obj.__module__` if it is not `None`.

    Args:
        obj: The object to get its type hints.
        localns: The local namespaces.
        include_extras: Whether to recursively include annotation metadata.

    Returns:
        The object type hints.
    
__module__N)globalnsr   r   )getattrsysmodules__dict__KeyErrorr   )r   r   r   module_namer!    r(   S/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pydantic/_internal/_fields.pyget_type_hints_infer_globalns   s    r*   c                   @  s   e Zd ZdZdZdS )PydanticMetadataz0Base class for annotation markers like `Strict`.r(   N)__name__r    __qualname____doc__	__slots__r(   r(   r(   r)   r+   <   s   r+   r   )metadatar   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r0   r(   r(   r)   pydantic_general_metadataB   s    	r3   )maxsizeztype[BaseMetadata])r   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dZdS )z7_general_metadata_cls.<locals>._PydanticGeneralMetadataz,Pydantic general metadata like `max_digits`.r   r2   c                 S  s
   || _ d S N)r%   )selfr0   r(   r(   r)   __init__V   s    z@_general_metadata_cls.<locals>._PydanticGeneralMetadata.__init__N)r,   r    r-   r.   r7   r(   r(   r(   r)   _PydanticGeneralMetadataS   s   r8   )annotated_typesr   r+   )r   r8   r(   r(   r)   r1   N   s    r1   z	type[Any]zdict[str, FieldInfo]r   None)clsfieldsconfig_wrapperr   c                 C  s@   |j r<t| }| D ]$\}}|jd u r||v r|| |_qd S r5   )Zuse_attribute_docstringsr   itemsdescription)r;   r<   r=   Zfields_docsann_name
field_infor(   r(   r)   _update_fields_from_docstrings\   s
    rB   )typevars_mapztype[BaseModel]ztuple[type[Any], ...]zdict[Any, Any] | Nonez%tuple[dict[str, FieldInfo], set[str]])r;   basesr=   types_namespacerC   r   c                  s   ddl m} t| |}| jdi }i }t }	| D ]\ }
 dkrJq6|jD ]} |rP|D ]P}t	| rbddl
m} t||r |jv sbtd  dt|  d| d	qbt fd
d|jD }td  d| d| dt qPt|
r|	  q6t|
t|  tr$|	  q6t s0q6| jrR dkrRtd dt| di d}|D ]}dd t|rt |ndD }t	| rh||u rqh |v rqh |vrƐqhtd  d| j d|j dt qhzt|  t}|tu r
tW nz ty    |v r2||
}nPi }| jddd D ]}| t|di  qF |v rxt!|  }n
||
}Y n<0 t"|
  |#|
|}zt$|   W n ty   Y n0 | jd } |j%v rt&d|| < q6|r|' D ]}|(|| qt)| || ||	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.
    r   r   __annotations__Zmodel_configr   zField "z" conflicts with member z of protected namespace "z".c                 3  s   | ]}  |s|V  qd S r5   
startswith).0xr@   r(   r)   	<genexpr>   s   z'collect_model_fields.<locals>.<genexpr>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)rI   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_fieldsZ__pydantic_decorators__z0you can't override a field with a computed field)*r<   r   r   r%   getsetr>   Zprotected_namespacesrH   hasattrmainr   
issubclassrU   	NameErrorr"   tuplewarningswarnUserWarningr   add_is_finalvar_with_default_valr   is_valid_field_nameZ__pydantic_root_model__dataclassesis_dataclassr-   AttributeErrorZfrom_annotation	__bases__updater   #_warn_on_nested_alias_in_annotationfrom_annotated_attributedelattrZcomputed_fields
ValueErrorvaluesapply_typevars_maprB   )r;   rD   r=   rE   rC   r   Z
type_hintsr   r<   Z
class_varsann_typeZprotected_namespacebr   Zvalid_namespacesZgeneric_originbasedataclass_fieldsdefaultrA   Zmodel_fields_lookuprJ   Z
decoratorsrQ   r(   rK   r)   collect_model_fieldsd   s    

















rs   str)rn   r@   c                 C  sl   ddl m} t| drh| jD ]J}t|rt|D ]0}t||r4|jd ur4t	
d| dt  qq4qd S )Nr   r   __args__z `alias` specification on field "z5" must be set on outermost annotation to take effect.)r<   r   rX   ru   r
   Zis_annotatedget_args
isinstancealiasr]   r^   r_   )rn   r@   r   Zanno_argZanno_type_argr(   r(   r)   rh      s    



rh   )type_valr   c                 C  sN   ddl m} t| sdS |tu r$dS t||rF|jtu rF|jd u rFdS dS d S )Nr   r   FT)r<   r   r   r   rw   rr   default_factory)ry   rz   r   r(   r(   r)   ra     s    ra   )rC   r=   ztype[StandardDataclass]zConfigWrapper | None)r;   rE   rC   r=   r   c                C  sV  ddl m} i }| j}tt| }tj| j}|durJi |j	|pFi }|
 D ]\}	}
t|
j||}t|rtqR|
js|
jtjkr|
jtjkrqRt|
j|r|
jjr|
jjdu rRtd|	 dddqR|||
j}n|||
}|||	< |jturRtt| |	||rRt| |	|j qR|r<| D ]}||| q(|durRt| || |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.
    r   r   NFzDataclass field zD has init=False and init_var=True, but these are mutually exclusive.zclashing-init-and-init-var)code)r<   r   __dataclass_fields__dictvarsr#   r$   rV   r    r%   r>   r
   Zeval_type_lenienttyper   initrr   rc   MISSINGr{   rw   Zinit_varr   ri   r   r"   setattrrl   rm   rB   )r;   rE   rC   r=   r   r<   rq   Zcls_localnsZsource_moduler@   Zdataclass_fieldrn   rA   rQ   r(   r(   r)   collect_dataclass_fields  sJ    



r   )rP   r   c                 C  s   |  d S )N_rG   rO   r(   r(   r)   rb   d  s    rb   c                 C  s   |  do|  d S )Nr   __rG   rO   r(   r(   r)   is_valid_privateattr_nameh  s    r   )NF)2r.   
__future__r   Z_annotationsrc   r#   r]   r   	functoolsr   typingr   r   Zpydantic_corer   Zpydantic.errorsr    r
   _configr   Z_docs_extractionr   _reprr   r   r   r   r   r9   r   r<   r   rY   r   Z_dataclassesr   Z_decoratorsr   r*   r+   r3   r1   rB   rs   rh   ra   r   rb   r   r(   r(   r(   r)   <module>   sL      H