o
    ¨ÝjÌ—  ã                   @   s  d dl Z d dlmZ d dlmZmZmZmZmZm	Z	m
Z
mZmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- d dl.m/Z/ d dl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 d dl8m9Z9 d d	l:m;Z; d d
l<m=Z= d dl>m?Z?m@Z@mAZAmBZBmCZCmDZDmZmEZEmFZFmGZGmHZHmIZImJZJ d dlKmLZL d dlMmNZN d dlOmPZQ d dlRmSZS zd dl>mTZT W n eUyÛ   d dl>mHZT Y nw dZVdZWeXdd… ZYeY› d�ZZeY› d�Z[eY› d�Z\eY› d�Z]eY› d�Z^de_de
e`df fdd„ZaeaeQƒZbebdk�rd nd!Zcd"ZPde_dd#fd$d%„ZdG d&d'„ d'e5ƒZeG d(d)„ d)ƒZfd*e4defd+d,„ZgG d-d.„ d.ƒZhG d/d0„ d0ƒZiG d1d2„ d2ƒZjed3d4d5ƒZked6d7d5ƒZled8d9d5ƒZmed:d;d5ƒZned<d=d5ƒZoed<d>d5ƒZpd?e_d@e1dAeddfdBdC„ZqdDe_d@e7dAeddfdEdF„Zrd@e7dAeddfdGdH„ZsdIe_d@ee1e7f dAeddfdJdK„Ztd@e7dAeddfdLdM„Zud@e1dAeddfdNdO„Zv			P	Pdad*e2dDe_dQee dRedSee dTeeT dUewdVewddfdWdX„ZxdYeee(f de_fdZd[„ZydYeee(f de_fd\d]„Zzd^e_deee_ef  fd_d`„Z{dS )bé    N)ÚConfigParser)	ÚAnyÚCallableÚDictÚListÚOptionalÚSetÚTupleÚTypeÚUnion)Ú	ErrorCode)Ú	ARG_NAMEDÚARG_NAMED_OPTÚARG_OPTÚARG_POSÚ	ARG_STAR2ÚMDEFÚArgumentÚAssignmentStmtÚBlockÚCallExprÚClassDefÚContextÚ	DecoratorÚEllipsisExprÚFuncBaseÚFuncDefÚJsonDictÚ
MemberExprÚNameExprÚPassStmtÚPlaceholderNodeÚRefExprÚStrExprÚ
SymbolNodeÚSymbolTableNodeÚTempNodeÚTypeInfoÚTypeVarExprÚVar)ÚOptions)ÚCheckerPluginInterfaceÚClassDefContextÚFunctionContextÚMethodContextÚPluginÚReportConfigContextÚSemanticAnalyzerPluginInterface)Údataclasses)Úset_callable_name)Úmake_wildcard_trigger)ÚAnyTypeÚCallableTypeÚInstanceÚNoneTypeÚ
OverloadedÚ
ProperTyper
   Ú	TypeOfAnyÚTypeTypeÚ	TypeVarIdÚTypeVarTypeÚ	UnionTypeÚget_proper_type)Úfill_typevars)Úget_unique_redefinition_name)Ú__version__)Úis_valid_field)Ú
TypeVarDef)r>   úpydantic-mypyzpydantic-mypy-metadataéûÿÿÿz.main.BaseModelz.env_settings.BaseSettingsz.main.ModelMetaclassz.fields.Fieldz.dataclasses.dataclassÚversionÚreturn.c                 C   s   t tt|  d¡d  d¡ƒƒS )Nú+r   Ú.)ÚtupleÚmapÚintÚ	partitionÚsplit©rH   © rR   úK/var/www/html/chatgpt/venv/lib/python3.10/site-packages/pydantic/v1/mypy.pyÚparse_mypy_versionW   s   rT   )r   i¢  ÚbuiltinsÚ__builtins__é   zTypingType[Plugin]c                 C   s   t S )z¼
    `version` is the mypy version string

    We might want to use this to print a warning if the mypy version being used is
    newer, or especially older, than we expect (or need).
    )ÚPydanticPluginrQ   rR   rR   rS   Úpluginb   s   rY   c                       sú   e Zd Zdeddf‡ fdd„Zdeddfdd	„Zdedeee	gdf  fd
d„Z
deddfdd„Zdedeeegef  fdd„Zdedeee	gdf  fdd„Zdedeeef fdd„Zde	ddfdd„Zde	ddfdd„Zdeddfdd„Z‡  ZS )rX   ÚoptionsrI   Nc                    s&   t |ƒ| _| j ¡ | _tƒ  |¡ d S ©N)ÚPydanticPluginConfigÚplugin_configÚto_dataÚ_plugin_dataÚsuperÚ__init__)ÚselfrZ   ©Ú	__class__rR   rS   ra   m   s   
zPydanticPlugin.__init__Úfullnamez+Optional[Callable[[ClassDefContext], None]]c                 C   s:   |   |¡}|rt|jtƒrtdd„ |jjD ƒƒr| jS d S )Nc                 s   ó   � | ]	}t |ƒtkV  qd S r[   )Úget_fullnameÚBASEMODEL_FULLNAME©Ú.0ÚbaserR   rR   rS   Ú	<genexpr>v   ó   € z5PydanticPlugin.get_base_class_hook.<locals>.<genexpr>)Úlookup_fully_qualifiedÚ
isinstanceÚnoder'   ÚanyÚmroÚ$_pydantic_model_class_maker_callback©rb   re   ÚsymrR   rR   rS   Úget_base_class_hookr   s
   
z"PydanticPlugin.get_base_class_hookc                 C   s   |t kr| jS d S r[   )ÚMODEL_METACLASS_FULLNAMEÚ)_pydantic_model_metaclass_marker_callback©rb   re   rR   rR   rS   Úget_metaclass_hookz   s   z!PydanticPlugin.get_metaclass_hookz+Optional[Callable[[FunctionContext], Type]]c                 C   s"   |   |¡}|r|jtkr| jS d S r[   )rn   re   ÚFIELD_FULLNAMEÚ_pydantic_field_callbackrt   rR   rR   rS   Úget_function_hook   s   
z PydanticPlugin.get_function_hookc                 C   s   |  d¡rtS d S )Nz	.from_orm)ÚendswithÚfrom_orm_callbackry   rR   rR   rS   Úget_method_hook…   s   
zPydanticPlugin.get_method_hookc                 C   s   |t krtdk rtjS dS )z€Mark pydantic.dataclasses as dataclass.

        Mypy version 1.1.1 added support for `@dataclass_transform` decorator.
        )é   r�   N)ÚDATACLASS_FULLNAMEÚMYPY_VERSION_TUPLEr2   Zdataclass_class_maker_callbackry   rR   rR   rS   Úget_class_decorator_hookŠ   s   z'PydanticPlugin.get_class_decorator_hookÚctxc                 C   ó   | j S )zjReturn all plugin config data.

        Used by mypy to determine if cache needs to be discarded.
        )r_   )rb   r…   rR   rR   rS   Úreport_config_data“   s   z!PydanticPlugin.report_config_datac                 C   s   t || jƒ}| ¡  d S r[   )ÚPydanticModelTransformerr]   Ú	transform)rb   r…   ZtransformerrR   rR   rS   rs   š   s   z3PydanticPlugin._pydantic_model_class_maker_callbackc                 C   s@   | j jrdS |jjj}|sJ dƒ‚t|jddƒrd|j_dS dS )zÓReset dataclass_transform_spec attribute of ModelMetaclass.

        Let the plugin handle it. This behavior can be disabled
        if 'debug_dataclass_transform' is set to True', for testing purposes.
        Nz-callback not passed from 'get_metaclass_hook'Údataclass_transform_spec)r]   Údebug_dataclass_transformÚclsÚinfoZdeclared_metaclassÚgetattrÚtyperŠ   )rb   r…   Zinfo_metaclassrR   rR   rS   rx   ž   s   
ÿz8PydanticPlugin._pydantic_model_metaclass_marker_callbackr
   c           	      C   s   |j }|jd dksJ dƒ‚|jd dksJ dƒ‚|jd }|jd }|r0|r0t|j|jƒ |S |rF|jd d }|d }t|tƒsD|S |S |rŽ|jd d }t|t	ƒrdt
dkr^|jd }n| ¡ d }t|tƒrŽt|jƒ}t|tƒrŒ|jrŒtdd	„ |jD ƒƒrŒ|j|gt|jƒ d
�}|S |S )ax  
        Extract the type of the `default` argument from the Field function, and use it as the return type.

        In particular:
        * Check whether the default and default_factory argument is specified.
        * Output an error if both are specified.
        * Retrieve the type of the argument which is specified, and use it as return type for the function.
        r   Údefaultz0"default" is no longer first argument in Field()r�   Údefault_factoryz9"default_factory" is no longer second argument in Field())r   iŽ  c                 s   s   � | ]}t |tƒV  qd S r[   )ro   r>   )rj   ÚargrR   rR   rS   rl   Ø   s   € z:PydanticPlugin._pydantic_field_callback.<locals>.<genexpr>)Úargs)Údefault_return_typeZcallee_arg_namesr“   Ú+error_default_and_default_factory_specifiedÚapiÚcontextÚ	arg_typesro   r   r9   rƒ   Úitemsr6   r@   Úret_typer7   ÚallZcopy_modifiedÚlen)	rb   r…   Zdefault_any_typeZdefault_argsZdefault_factory_argsZdefault_typeZdefault_argZdefault_factory_typerš   rR   rR   rS   r|   «   s>   	


é


ÿþýz'PydanticPlugin._pydantic_field_callback)Ú__name__Ú
__module__Ú__qualname__r*   ra   Ústrrv   r   r   r,   rz   r}   r.   r
   r€   r„   r0   r   r   r‡   rs   rx   r-   r|   Ú__classcell__rR   rR   rc   rS   rX   l   s       	rX   c                   @   sb   e Zd ZU dZeed< eed< eed< eed< eed< dedd	fd
d„Zdee	e
f fdd„Zd	S )r\   )Úinit_forbid_extraÚ
init_typedÚwarn_required_dynamic_aliasesÚwarn_untyped_fieldsr‹   r¢   r£   r¤   r¥   r‹   rZ   rI   Nc                 C   s²   |j d u rd S t|j ƒ}|d ur:| di ¡ di ¡}| jD ]}| |d¡}t|tƒs1td|› �ƒ‚t| ||ƒ qd S tƒ }| 	|j ¡ | jD ]}|j
t|dd�}t| ||ƒ qFd S )NÚtoolrF   Fz/Configuration value must be a boolean for key: )Úfallback)Úconfig_fileÚ
parse_tomlÚgetÚ	__slots__ro   ÚboolÚ
ValueErrorÚsetattrr   ÚreadÚ
getbooleanÚCONFIGFILE_KEY)rb   rZ   Ztoml_configÚconfigÚkeyZsettingr]   rR   rR   rS   ra   ï   s"   



ü
þzPydanticPluginConfig.__init__c                    s   ‡ fdd„ˆ j D ƒS )Nc                    s   i | ]}|t ˆ |ƒ“qS rR   )rŽ   )rj   r³   ©rb   rR   rS   Ú
<dictcomp>  ó    z0PydanticPluginConfig.to_data.<locals>.<dictcomp>)r«   r´   rR   r´   rS   r^     ó   zPydanticPluginConfig.to_data)r�   rž   rŸ   r«   r¬   Ú__annotations__r*   ra   r   r    r   r^   rR   rR   rR   rS   r\   á   s   
 r\   r…   c                 C   sÂ   | j }t|tƒr|j}t|tƒrt|jtƒr|j}nt|tƒr"|}nd|› d|jj› d�}t	|| j
| jƒ | jS |j j t¡}|du rF| jS | di ¡ d¡}|dur^tt|j ƒ| j
| jƒ | jS )z3
    Raise an error if orm_mode is not enabled
    z
ctx.type: ú
 (of type ú)Nr²   Úorm_modeT)r�   ro   r<   Úitemr6   rš   r7   rd   r�   Úerror_unexpected_behaviorr–   r—   r”   Úmetadatarª   ÚMETADATA_KEYÚerror_from_ormÚget_name)r…   Zctx_typeZ
model_typeÚdetailZpydantic_metadatar»   rR   rR   rS   r     s"   

r   c                   @   sˆ  e Zd ZU h d£Zee ed< dededdfdd„Z	d5d	d
„Z
d5dd„Zd6dd„Zddded fdd„Zded dddeddfdd„Zded ddfdd„Zded deddfdd„Zdeded fdd „Zed!ed"ed#edefd$d%„ƒZed&ee defd'd(„ƒZed"edeee ef fd)d*„ƒZded d+ed,ed-edee f
d.d/„Zded dddefd0d1„Z eded d2edefd3d4„ƒZ!dS )7rˆ   >   Úallow_population_by_field_nameÚalias_generatorr»   Úallow_mutationÚfrozenÚextraÚtracked_config_fieldsr…   r]   rI   Nc                 C   s   || _ || _d S r[   )Ú_ctxr]   )rb   r…   r]   rR   rR   rS   ra   )  s   
z!PydanticModelTransformer.__init__c                 C   sœ   | j }|jj}|  ¡  |  ¡ }|  |¡}tdd„ |jdd… D ƒƒ}|  |||¡ |  	|¡ | j
||jdu p:|jdu d� dd	„ |D ƒ| ¡ d
œ|jt< dS )a¨  
        Configures the BaseModel subclass according to the plugin settings.

        In particular:
        * determines the model config and fields,
        * adds a fields-aware signature for the initializer and construct methods
        * freezes the class if allow_mutation = False or frozen = True
        * stores the fields, config, and if the class is settings in the mypy metadata for access by subclasses
        c                 s   rf   r[   )rg   ÚBASESETTINGS_FULLNAMEri   rR   rR   rS   rl   =  rm   z5PydanticModelTransformer.transform.<locals>.<genexpr>NéÿÿÿÿFT)rÆ   c                 S   s   i | ]}|j | ¡ “qS rR   )ÚnameÚ	serialize©rj   ÚfieldrR   rR   rS   rµ   B  r¶   z6PydanticModelTransformer.transform.<locals>.<dictcomp>)Úfieldsr²   )rÉ   rŒ   r�   Úadjust_validator_signaturesÚcollect_configÚcollect_fieldsrq   rr   Úadd_initializerÚadd_construct_methodÚ
set_frozenrÅ   rÆ   Úset_values_dictr¾   r¿   )rb   r…   r�   r²   rÐ   Úis_settingsrR   rR   rS   r‰   -  s   


þz"PydanticModelTransformer.transformc                 C   sh   | j jjj ¡ D ])\}}t|jtƒr1|jjd }t|t	ƒr1t|j
tƒr1|j
jt› d�kr1d|jj_qdS )a[  When we decorate a function `f` with `pydantic.validator(...), mypy sees
        `f` as a regular method taking a `self` instance, even though pydantic
        internally wraps `f` with `classmethod` if necessary.

        Teach mypy this by marking any function whose outermost decorator is a
        `validator()` call as a classmethod.
        r   z.class_validators.validatorTN)rÉ   rŒ   r�   Únamesr™   ro   rp   r   Zoriginal_decoratorsr   Úcalleer   re   Ú
_NAMESPACEÚfuncÚis_class)rb   rÌ   ru   Z	first_decrR   rR   rS   rÑ   F  s   ÿ
þ
€øz4PydanticModelTransformer.adjust_validator_signaturesÚModelConfigDatac           	      C   sâ   | j }|j}tƒ }|jjD ]2}t|tƒsq|jdkr?|jjD ]}t|tƒs&q| 	|  
|¡¡ q|jr?|js?| jjr?t|j|ƒ q|jjdd… D ]&}t|jvrPqH|j tt|ƒƒ¡ |jt d  ¡ D ]
\}}| ||¡ qcqH|S )zz
        Collects the values of the config attributes that are used by the plugin, accounting for parent classes.
        ZConfigr�   Nr²   )rÉ   rŒ   rÞ   ÚdefsÚbodyro   r   rÌ   r   ÚupdateÚget_config_updateÚhas_alias_generatorrÃ   r]   r¤   Úerror_required_dynamic_aliasesr–   r�   rr   r¿   r¾   Úadd_plugin_dependencyr4   rg   r™   Ú
setdefault)	rb   r…   rŒ   r²   ÚstmtÚsubstmtr�   rÌ   ÚvaluerR   rR   rS   rÒ   X  s6   


ÿþý€
ÿz'PydanticModelTransformer.collect_configÚmodel_configÚPydanticModelFieldc                    sÎ  | j }| j j}g }tƒ }|jjD ]x}t|tƒsq|jd }t|tƒr't	|j
ƒs(q|js5| jjr5t|j|ƒ |jj |j
¡}|du rBq|j}	t|	tƒrKqt|	tƒsQq|	jrUq|  |||¡}
|  |¡\}}|rr|jsr| jjrrt|j|ƒ | t|j
|
|||j|jd�¡ |  |j
¡ q| !¡ }|jj"dd… D ]O}t#|j$vr�q•g }|j %t&t'|ƒƒ¡ |j$t# d  (¡ D ]-\‰ }ˆ |vrËt )||¡}|  ˆ ¡ | |¡ q²‡ fdd„|D ƒ\}| *|¡ | |¡ q²|| }q•|S )zR
        Collects the fields for the model, accounting for parent classes
        r   N©rÌ   Úis_requiredÚaliasÚhas_dynamic_aliasÚlineÚcolumnr�   rÐ   c                 3   s   � | ]
}|j ˆ kr|V  qd S r[   ©rÌ   )rj   Úarò   rR   rS   rl   Å  s   € z:PydanticModelTransformer.collect_fields.<locals>.<genexpr>)+rÉ   rŒ   Úsetrß   rà   ro   r   Úlvaluesr   rD   rÌ   Z
new_syntaxr]   r¥   Úerror_untyped_fieldsr–   r�   rÙ   rª   rp   r!   r)   Zis_classvarÚget_is_requiredÚget_alias_inforÃ   r¤   rä   Úappendrë   rð   rñ   ÚaddÚcopyrr   r¿   r¾   rå   r4   rg   r™   ÚdeserializeÚremove)rb   rê   r…   rŒ   rÐ   Zknown_fieldsrç   Úlhsru   rp   rí   rî   rï   Z
all_fieldsr�   Zsuperclass_fieldsÚdatarÏ   rR   rò   rS   rÓ   w  st   



ÿþýúÿ




z'PydanticModelTransformer.collect_fieldsrÐ   r²   rØ   c           
      C   s”   | j }| jj}|jdu}|pt|jo|j ƒ}| j||||d�}|  ||¡s7tdƒ}	| 	t
|	ttjƒdtƒ¡ d|jjjvrHt|d|tƒ ƒ dS dS )z°
        Adds a fields-aware `__init__` method to the class.

        The added `__init__` will be annotated with types vs. all `Any` depending on the plugin settings.
        T©ÚtypedÚforce_all_optionalÚ	use_aliasÚkwargsNra   )rÉ   r]   r£   rÃ   r¬   rã   Úget_field_argumentsÚshould_init_forbid_extrar)   rù   r   r5   r;   Úexplicitr   rŒ   r�   rÙ   Ú
add_methodr8   )
rb   rÐ   r²   rØ   r…   r  r  r  Zinit_argumentsÚvarrR   rR   rS   rÔ   Ë  s   
ÿÿÿz(PydanticModelTransformer.add_initializerc              	   C   sJ  | j }|j t› d�|j t› d�¡g¡}t|tƒ gƒ}ttd|ƒ|dtƒ}| j	|dddd�}|g| }|j t› d�¡}d	}|j
jd
 | }	tdkrst||	tdkr\td|j
jd d�ntdƒg |ttjƒƒ}
t||	g |ttjƒƒ}nt||	dg |ƒ}
t||	g |ƒ}tt|ƒ|j
jj|< t|
tƒr”|
}nt|
ƒ}t|d||||
dd� dS )zç
        Adds a fully typed `construct` classmethod to the class.

        Similar to the fields-aware __init__ method, but always uses the field names (not aliases),
        and does not treat settings fields as optional.
        z.setz.strZ_fields_setNTFr   z.objectZ_PydanticBaseModelrK   )r�   é   )r�   é   rË   z
.construct)Ú	namespaceZ	construct)Úreturn_typeÚ	self_typeÚtvar_defÚis_classmethod)rÉ   r–   Ú
named_typeÚBUILTINS_NAMEr?   r8   r   r)   r   r  rŒ   re   rƒ   r>   r=   r5   r;   Zfrom_omitted_genericsr(   rE   r%   r   r�   rÙ   ro   r  )rb   rÐ   r…   Zset_strZoptional_set_strZfields_set_argumentZconstruct_argumentsÚobj_typeZself_tvar_nameZtvar_fullnameZtvdZself_tvar_exprr  rR   rR   rS   rÕ   á  sT   $
ÿöû

ùz-PydanticModelTransformer.add_construct_methodrÆ   c           
   	   C   sú   | j }|jj}|D ]q}|j |j¡}|durX|j}t|tƒr"||_	q	t|t
ƒr1|jjs1|j ¡  q	zt|ƒ}W n tyD   t|ƒ}Y nw d|› d|j› d�}	t|	|j|jƒ q	|j|dd�}||_||_	t|ƒd t|ƒ |_tt|ƒ|jt|ƒ< q	dS )z°
        Marks all fields as properties so that attempts to set them trigger mypy errors.

        This is the same approach used by the attrs and dataclasses plugins.
        Nzsym_node.node: r¹   rº   F)r  rK   )rÉ   rŒ   r�   rÙ   rª   rÌ   rp   ro   r)   Zis_propertyr!   r–   Zfinal_iterationZdeferr    Ú	TypeErrorÚreprrd   r½   Úto_varrg   rÁ   Ú	_fullnamer%   r   )
rb   rÐ   rÆ   r…   r�   rÏ   Zsym_noder	  Zvar_strrÂ   rR   rR   rS   rÖ     s.   
þéz#PydanticModelTransformer.set_frozenrè   c                 C   s   |j d }t|tƒr|j| jv sdS |jdkrAt|jtƒr$|jjdk}nt|jtƒr1|jjdk}nt	|j| j
j|ƒ dS t|d�S |jdkr[d}t|jtƒrV|jjdkrVd	}t|d
�S t|jtƒru|jjdv rutdi |j|jjdki¤ŽS t	|j| j
j|ƒ dS )zß
        Determines the config update due to a single statement in the Config class definition.

        Warns if a tracked config attribute is set to a value the plugin doesn't know how to interpret (e.g., an int)
        r   NrÇ   Zforbid)Úforbid_extrarÄ   Tzbuiltins.NoneF)rã   )úbuiltins.Truezbuiltins.Falser  rR   )rõ   ro   r   rÌ   rÈ   Úrvaluer#   ré   r   Úerror_invalid_config_valuerÉ   r–   rÞ   re   )rb   rè   rþ   r  rã   rR   rR   rS   râ   <  s(   




z*PydanticModelTransformer.get_config_updaterŒ   rç   rþ   c                 C   s¼   |j }t|tƒrt| j|j jƒ}t |¡ S t|t	ƒrYt|j
tƒrY|j
jtkrYt|j|jƒD ]\}}|du s;|dkrB|jtu   S |dkrI dS q/t| j|j jƒ}t |¡ S t|tƒS )zg
        Returns a boolean indicating whether the field defined in `stmt` is a required field.
        Nr�   r‘   F)r  ro   r&   r@   r�   rÌ   r�   rˆ   Útype_has_implicit_defaultr   rÚ   r"   re   r{   Úzipr“   Ú	arg_namesrd   r   )rŒ   rç   rþ   ÚexprZ
value_typer’   rÌ   rR   rR   rS   r÷   X  s   
"ÿ
z(PydanticModelTransformer.get_is_requiredÚtype_c                 C   s4   t | tƒrdS t | tƒrtdd„ | jD ƒƒrdS dS )zº
        Returns True if the passed type will be given an implicit default value.

        In pydantic v1, this is the case for Optional types and Any (with default value None).
        Tc                 s   s$   � | ]}t |tƒpt |tƒV  qd S r[   )ro   r8   r5   )rj   r¼   rR   rR   rS   rl   |  s   € 
ÿzEPydanticModelTransformer.type_has_implicit_default.<locals>.<genexpr>F)ro   r5   r?   rq   r™   )r   rR   rR   rS   r  r  s   
ÿz2PydanticModelTransformer.type_has_implicit_defaultc                 C   s‚   | j }t|tƒr
dS t|tƒrt|jtƒr|jjtksdS t|j	ƒD ]\}}|dkr+q"|j
| }t|tƒr<|jdf  S  dS dS )a   
        Returns a pair (alias, has_dynamic_alias), extracted from the declaration of the field defined in `stmt`.

        `has_dynamic_alias` is True if and only if an alias is provided, but not as a string literal.
        If `has_dynamic_alias` is True, `alias` will be None.
        )NFrî   F)NT)r  ro   r&   r   rÚ   r"   re   r{   Ú	enumerater  r“   r#   ré   )rç   r  ÚiZarg_namer’   rR   rR   rS   rø   ƒ  s"   
ÿ
ÿ

z'PydanticModelTransformer.get_alias_infor  r  r  c                    s&   | j jj‰‡ ‡‡‡fdd„|D ƒ}|S )zË
        Helper function used during the construction of the `__init__` and `construct` method signatures.

        Returns a list of mypy Argument instances for use in the generated signatures.
        c                    s(   g | ]}ˆr	|j s|jˆˆˆ ˆd �‘qS ))r  Úforce_optionalr  )rï   Úto_argumentrÎ   ©r  r�   r  r  rR   rS   Ú
<listcomp>©  s    ýýÿz@PydanticModelTransformer.get_field_arguments.<locals>.<listcomp>)rÉ   rŒ   r�   )rb   rÐ   r  r  r  Ú	argumentsrR   r%  rS   r     s
   
þz,PydanticModelTransformer.get_field_argumentsc                 C   s.   |j s|  |t|jƒ¡rdS |jrdS | jjS )aH  
        Indicates whether the generated `__init__` should get a `**kwargs` at the end of its signature

        We disallow arbitrary kwargs if the extra config setting is "forbid", or if the plugin config says to,
        *unless* a required dynamic alias is present (since then we can't determine a valid signature).
        FT)rÃ   Úis_dynamic_alias_presentr¬   rã   r  r]   r¢   )rb   rÐ   r²   rR   rR   rS   r  °  s   z1PydanticModelTransformer.should_init_forbid_extrarã   c                 C   s8   | D ]}|j r
 dS q|r| D ]
}|jdu r dS qdS )zš
        Returns whether any fields on the model have a "dynamic alias", i.e., an alias that cannot be
        determined during static analysis.
        TNF)rï   rî   )rÐ   rã   rÏ   rR   rR   rS   r(  ¾  s   ÿ
ÿz1PydanticModelTransformer.is_dynamic_alias_present)rI   N)rI   rÞ   )"r�   rž   rŸ   rÈ   r   r    r¸   r,   r\   ra   r‰   rÑ   rÒ   r   rÓ   r¬   rÔ   rÕ   rÖ   r   r   râ   Ústaticmethodr   r   r÷   r:   r  r	   rø   r   r  r  r(  rR   rR   rR   rS   rˆ     s>   
 	


T:! ÿÿÿÿ
þ rˆ   c                   @   sŽ   e Zd Zdededee dededefdd„Zd	ed
ede	fdd„Z
d	ededed
edef
dd„Zdefdd„Zed	ededd fdd„ƒZdS )rë   rÌ   rí   rî   rï   rð   rñ   c                 C   ó(   || _ || _|| _|| _|| _|| _d S r[   rì   )rb   rÌ   rí   rî   rï   rð   rñ   rR   rR   rS   ra   Ï  s   
zPydanticModelField.__init__r�   r  rI   c                 C   s,   | j }|r| jd ur| j}t||| j  jƒS r[   )rÌ   rî   r)   r�   )rb   r�   r  rÌ   rR   rR   rS   r  Ù  s   zPydanticModelField.to_varr  r#  c                 C   sV   |r|| j  jd ur|| j  j}nttjƒ}t|  ||¡|d |s#| js'td�S t	d�S )N)ÚvariableÚtype_annotationZinitializerÚkind)
rÌ   r�   r5   r;   r  r   r  rí   r   r   )rb   r�   r  r#  r  r,  rR   rR   rS   r$  ß  s   

üüzPydanticModelField.to_argumentc                 C   r†   r[   )Ú__dict__r´   rR   rR   rS   rÍ   ë  s   zPydanticModelField.serializerÿ   c                 C   s   | di |¤ŽS )NrR   rR   )rŒ   r�   rÿ   rR   rR   rS   rü   î  s   zPydanticModelField.deserializeN)r�   rž   rŸ   r    r¬   r   rN   ra   r'   r)   r  r   r$  r   rÍ   Úclassmethodrü   rR   rR   rR   rS   rë   Î  s&    ÿÿÿÿÿ
ÿ
rë   c                   @   s–   e Zd Z						ddee dee dee dee dee dee fdd	„Zd
eeef fdd„Z	ded  d
dfdd„Z
deded
dfdd„ZdS )rÞ   Nr  rÅ   rÆ   r»   rÃ   rã   c                 C   r*  r[   )r  rÅ   rÆ   r»   rÃ   rã   )rb   r  rÅ   rÆ   r»   rÃ   rã   rR   rR   rS   ra   ô  s   	
zModelConfigData.__init__rI   c                 C   s   dd„ | j  ¡ D ƒS )Nc                 S   s   i | ]\}}|d ur||“qS r[   rR   )rj   ÚkÚvrR   rR   rS   rµ     s    z3ModelConfigData.set_values_dict.<locals>.<dictcomp>)r.  r™   r´   rR   rR   rS   r×     r·   zModelConfigData.set_values_dictr²   c                 C   s2   |d u rd S |  ¡  ¡ D ]
\}}t| ||ƒ qd S r[   )r×   r™   r®   )rb   r²   r0  r1  rR   rR   rS   rá     s
   ÿzModelConfigData.updater³   ré   c                 C   s"   t | |ƒd u rt| ||ƒ d S d S r[   )rŽ   r®   )rb   r³   ré   rR   rR   rS   ræ     s   ÿzModelConfigData.setdefault)NNNNNN)r�   rž   rŸ   r   r¬   ra   r   r    r   r×   rá   ræ   rR   rR   rR   rS   rÞ   ó  s.    ùþýüûú
ùrÞ   zpydantic-ormzInvalid from_orm callZPydanticzpydantic-configzInvalid config valuezpydantic-aliaszDynamic alias disallowedzpydantic-unexpectedzUnexpected behaviorzpydantic-fieldzUntyped field disallowedzInvalid Field defaultsÚ
model_namer–   r—   c                 C   ó   |j d| › d�|td� d S )Nú"z" does not have orm_mode=True©Úcode)ÚfailÚ	ERROR_ORM)r2  r–   r—   rR   rR   rS   rÀ     ó   rÀ   rÌ   c                 C   r3  )NzInvalid value for "Config.r4  r5  )r7  ÚERROR_CONFIG)rÌ   r–   r—   rR   rR   rS   r    r9  r  c                 C   ó   | j d|td� d S )Nz#Required dynamic aliases disallowedr5  )r7  ÚERROR_ALIAS©r–   r—   rR   rR   rS   rä   "  r·   rä   rÂ   c                 C   s4   d}d| › d�}|d|› d�7 }|j ||td� d S )Nz6https://github.com/pydantic/pydantic/issues/new/choosez7The pydantic mypy plugin ran into unexpected behavior: Ú
z&Please consider reporting this bug at z so we can try to fix it!r5  )r7  ÚERROR_UNEXPECTED)rÂ   r–   r—   ÚlinkZfull_messagerR   rR   rS   r½   &  s   r½   c                 C   r;  )NzUntyped fields disallowedr5  )r7  ÚERROR_UNTYPEDr=  rR   rR   rS   rö   0  r·   rö   c                 C   r;  )Nz>Field default and default_factory cannot be specified togetherr5  )r7  ÚERROR_FIELD_DEFAULTSr=  rR   rR   rS   r•   4  r·   r•   Fr“   r  r  r  r  Úis_newc                 C   s  | j j}||jv r |j| }	|	jr t|	jtƒr | j jj 	|	j¡ |p%t
|ƒ}|s*|r8ttdƒt |¡dtƒg}
n|p=t
|ƒ}ttdƒ|dtƒg}
|
| }g g g }}}|D ]}|js_J dƒ‚| |j¡ | t|jƒ¡ | |j¡ qV| j t› d�¡}t||||||rˆ|gndd�}t||ttƒ gƒƒ}||_t||ƒ|_||_t|ƒd | |_|j |_ ||jv rÂt!||jƒ}|j| |j|< |rêd|_"t||jƒ}||_|j|_d|_#t$|t%d	ƒg|ƒ}|j |_ t&t'|ƒ}	nt&t'|ƒ}	d|	_|	|j|< |j(jj |¡ dS )
z}
    Adds a new method to a class.

    This can be dropped if/when https://github.com/python/mypy/issues/7301 is merged
    Ú_clsNZ__pydantic_self__z"All arguments must be fully typed.z	.function)Ú	variablesrK   Tr/  ))rŒ   r�   rÙ   Zplugin_generatedro   rp   r   rß   rà   rý   rA   r   r)   r<   Zmake_normalizedr   r,  rù   rÁ   r+  r-  r–   r  r  r6   r   r    r3   r�   rÝ   rg   r  rð   rB   Zis_decoratedr  r   r   r%   r   Zdefn)r…   rÌ   r“   r  r  r  r  rC  r�   ru   Úfirstr˜   r  Z	arg_kindsr’   Zfunction_typeÚ	signaturerÜ   Zr_namer1  ÚdecrR   rR   rS   r  8  sV   

ÿ


r  Úxc                 C   ó   | j }t|ƒr
|ƒ S |S ©zc
    Used for compatibility with mypy 0.740; can be dropped once support for 0.740 is dropped.
    )re   Úcallable©rI  ÚfnrR   rR   rS   rg   ‹  ó   rg   c                 C   rJ  rK  )rÌ   rL  rM  rR   rR   rS   rÁ   •  rO  rÁ   r¨   c                 C   s¸   |   d¡sd S d}tjdkrdd l}n-zdd l}W n& ty?   d}zdd l}W n ty<   dd l}| d¡ Y Y d S w Y nw t	| |ƒ�}| 
|¡W  d   ƒ S 1 sUw   Y  d S )Nz.tomlÚrb)é   r  r   ÚrzJNo TOML parser installed, cannot read configuration from `pyproject.toml`.)r~   ÚsysÚversion_infoÚtomllibÚtomliÚImportErrorÚtomlÚwarningsÚwarnÚopenÚload)r¨   Z	read_modeZtoml_rY  ÚrfrR   rR   rS   r©   Ÿ  s*   



üÿü$ÿr©   )NNFF)|rS  Úconfigparserr   Útypingr   r   r   r   r   r   r	   r
   Z
TypingTyper   Zmypy.errorcodesr   Z
mypy.nodesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   Zmypy.optionsr*   Zmypy.pluginr+   r,   r-   r.   r/   r0   r1   Zmypy.pluginsr2   Zmypy.semanalr3   Zmypy.server.triggerr4   Z
mypy.typesr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   Zmypy.typevarsrA   Z	mypy.utilrB   Zmypy.versionrC   Zmypy_versionZpydantic.v1.utilsrD   rE   rW  r±   r¿   r�   rÛ   rh   rÊ   rw   r{   r‚   r    rN   rT   rƒ   r  rY   rX   r\   r   rˆ   rë   rÞ   r8  r:  r<  r?  rA  rB  rÀ   r  rä   r½   rö   r•   r¬   r  rg   rÁ   r©   rR   rR   rR   rS   Ú<module>   s°    ,|$	<þ





u%   2%ÿ
ÿÿ
þ
	øÿþýüûúùø

öS
"
