
    zi|                       d Z ddlmZ ddl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 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,m-Z-m.Z. dd	l/m0Z0 dd
l1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 ddl9m:Z: ddl;m<Z< ddl=m>Z> ddl?m@Z@ ddlAmBZB ddlCmDZD ddlEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZP ddlQmRZR ddlSmTZT ddlUmVZW ddlXmYZY ddlZm[Z[ 	 ddlEm\Z\ n# e]$ r	 ddlEmNZ\ Y nw xY wdZ^dZ_dZ`dZadZbdZcdZdd Zed!Zfh d"Zg e[eW          Zhehd#k    rd$nd%Zid&ZVdid+Zj G d, d-e6          Zk G d. d/          Zldjd3Zm G d4 d5          Zn G d6 d7          Zo G d8 d9          Zp ed:d;d<          Zq ed=d>d<          Zr ed?d@d<          Zs edAdBd<          Zt edCdDd<          Zu edCdEd<          Zv edCdFd<          ZwdkdMZxdldPZydmdQZzdndTZ{dmdUZ|dodVZ}dodWZ~	 	 	 dpdqdeZdrdhZdS )sz^This module includes classes and functions designed specifically for use with the mypy plugin.    )annotationsN)ConfigParser)AnyCallableIterator)	ErrorCode)expand_typeexpand_type_by_instance)	ARG_NAMEDARG_NAMED_OPTARG_OPTARG_POS	ARG_STAR2MDEFArgumentAssignmentStmtBlockCallExprClassDefContext	DecoratorDictExprEllipsisExpr
ExpressionFuncDefIfStmtJsonDict
MemberExprNameExprPassStmtPlaceholderNodeRefExpr	StatementStrExprSymbolTableNodeTempNode	TypeAliasTypeInfoVar)Options)CheckerPluginInterfaceClassDefContextFunctionContextMethodContextPluginReportConfigContextSemanticAnalyzerPluginInterface)dataclasses)deserialize_and_fixup_type)set_callable_name)make_wildcard_trigger)state)map_type_from_supertype)AnyTypeCallableTypeInstanceNoneType
OverloadedType	TypeOfAnyTypeTypeTypeVarType	UnionTypeget_proper_type)fill_typevars)get_unique_redefinition_name)__version__)_fields)parse_mypy_version)
TypeVarDef)r@   pydantic-mypyzpydantic-mypy-metadatazpydantic.main.BaseModelz#pydantic_settings.main.BaseSettingszpydantic.root_model.RootModelz5pydantic._internal._model_construction.ModelMetaclasszpydantic.fields.Fieldzpydantic.dataclasses.dataclass.pydantic.functional_validators.model_validator>   *pydantic.functional_serializers.serializer.pydantic.deprecated.class_validators.validator.pydantic.functional_validators.field_validator0pydantic.functional_serializers.model_serializer3pydantic.deprecated.class_validators.root_validatorrJ   )r   i  builtins__builtins__   versionstrreturntype[Plugin]c                    t           S )a!  `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).

    Args:
        version: The mypy version string.

    Return:
        The Pydantic mypy plugin type.
    )PydanticPlugin)rS   s    X/var/www/tmov.alphamb/tmov_inventario/venv/lib/python3.11/site-packages/pydantic/mypy.pypluginrZ   r   s
         c                  l     e Zd ZdZd fdZdd
ZddZd dZd!dZddZ	d"dZ
d#dZd$dZd%dZ xZS )&rX   zThe Pydantic mypy plugin.optionsr*   rU   Nonec                    t          |          | _        | j                                        | _        t	                                          |           d S N)PydanticPluginConfigplugin_configto_data_plugin_datasuper__init__)selfr]   	__class__s     rY   rf   zPydanticPlugin.__init__   sH    1':: .6688!!!!!r[   fullnamerT   (Callable[[ClassDefContext], bool] | Nonec                    |                      |          }|rDt          |j        t                    r*t	          d |j        j        D                       r| j        S dS )zUpdate Pydantic model class.c              3  6   K   | ]}|j         t          k    V  d S r`   )ri   BASEMODEL_FULLNAME.0bases     rY   	<genexpr>z5PydanticPlugin.get_base_class_hook.<locals>.<genexpr>   s*      PP44=$66PPPPPPr[   N)lookup_fully_qualified
isinstancenoder(   anymro$_pydantic_model_class_maker_callbackrg   ri   syms      rY   get_base_class_hookz"PydanticPlugin.get_base_class_hook   sd    ))(33 	A:ch11 	APP38<PPPPP A@@tr[   (Callable[[ClassDefContext], None] | Nonec                *    |t           k    r| j        S dS )z,Update Pydantic `ModelMetaclass` definition.N)MODEL_METACLASS_FULLNAME)_pydantic_model_metaclass_marker_callbackrg   ri   s     rY   get_metaclass_hookz!PydanticPlugin.get_metaclass_hook   s    ///AAtr[   (Callable[[FunctionContext], Type] | Nonec                b    |                      |          }|r|j        t          k    r| j        S dS )z/Adjust the return type of the `Field` function.N)rr   ri   FIELD_FULLNAME_pydantic_field_callbackrx   s      rY   get_function_hookz PydanticPlugin.get_function_hook   s7    ))(33 	13<>1100tr[   &Callable[[MethodContext], Type] | Nonec                >    |                     d          rt          S dS )z-Adjust return type of `from_orm` method call.z	.from_ormN)endswithfrom_attributes_callbackr   s     rY   get_method_hookzPydanticPlugin.get_method_hook   s#    [)) 	,++tr[   c                J    |t           k    rt          dk     rt          j        S dS )zMark pydantic.dataclasses as dataclass.

        Mypy version 1.1.1 added support for `@dataclass_transform` decorator.
        )   r   N)DATACLASS_FULLNAMEMYPY_VERSION_TUPLEr2   dataclass_class_maker_callbackr   s     rY   get_class_decorator_hookz'PydanticPlugin.get_class_decorator_hook   s)    
 ))).@6.I.I==tr[   ctxr0   dict[str, Any]c                    | j         S )zjReturn all plugin config data.

        Used by mypy to determine if cache needs to be discarded.
        )rd   )rg   r   s     rY   report_config_dataz!PydanticPlugin.report_config_data   s    
   r[   r,   boolc                v    t          |j        |j        |j        | j                  }|                                S r`   )PydanticModelTransformerclsreasonapirb   	transform)rg   r   transformers      rY   rw   z3PydanticPlugin._pydantic_model_class_maker_callback   s0    .sw
CGTM_``$$&&&r[   c                    | j         j        rdS |j        j        j        }|s
J d            t          |j        dd          rd|j        _        dS dS )zReset 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)rb   debug_dataclass_transformr   infodeclared_metaclassgetattrtyper   )rg   r   info_metaclasss      rY   r~   z8PydanticPlugin._pydantic_model_metaclass_marker_callback   sn     7 	F8NNNNNN>&(BDII 	@;?N888	@ 	@r[   r-   r=   c                  	 |j         	|j        d         dk    s
J d            |j        d         dk    s
J d            |j        d         }|j        d         }|r|rt          |j        |j                   	S |r3|j        d         d         }|d         }t          |t                    s|S n|r|j        d         d         }t          |t                    r|j
        d         }t          |t                    rU|j        }t          |dd          }|r9t          d	 |D                       r t          	fd
|D                       |_        |S 	S )ao  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()argsNc              3  @   K   | ]}t          |t                    V  d S r`   )rs   r@   )ro   args     rY   rq   z:PydanticPlugin._pydantic_field_callback.<locals>.<genexpr>   s,      HHC:c;77HHHHHHr[   c              3     K   | ]}V  d S r`    )ro   _default_any_types     rY   rq   z:PydanticPlugin._pydantic_field_callback.<locals>.<genexpr>   s$      -M-M1.>-M-M-M-M-M-Mr[   )default_return_typecallee_arg_namesr   +error_default_and_default_factory_specifiedr   context	arg_typesrs   r   r<   itemsr9   ret_typer   alltuple)
rg   r   default_argsdefault_factory_argsdefault_typedefault_argdefault_factory_typer   r   r   s
            @rY   r   z'PydanticPlugin._pydantic_field_callback   s    2#A&)3335g333#A&*;;;;=x;;;x{"x{ 	$0 	$7MMM## 	 =+A.L&q/K k<88 $##$ " 	 #&=#3A#6  .
;; E';'A!'D$.== 	 /8 x66 NHH4HHHHH N(--M-M-M-M-M-M-M(M(Mr[   r]   r*   rU   r^   )ri   rT   rU   rj   )ri   rT   rU   r{   )ri   rT   rU   r   )ri   rT   rU   r   )r   r0   rU   r   )r   r,   rU   r   )r   r,   rU   r^   )r   r-   rU   r=   )__name__
__module____qualname____doc__rf   rz   r   r   r   r   r   rw   r~   r   __classcell__)rh   s   @rY   rX   rX      s        ##" " " " " "
               ! ! ! !' ' ' '@ @ @ @.  .  .  .  .  .  .  . r[   rX   c                  P    e Zd ZU dZdZded<   ded<   ded<   ded<   ddZddZdS )ra   a  A Pydantic mypy plugin config holder.

    Attributes:
        init_forbid_extra: Whether to add a `**kwargs` at the end of the generated `__init__` signature.
        init_typed: Whether to annotate fields in the generated `__init__`.
        warn_required_dynamic_aliases: Whether to raise required dynamic aliases error.
        debug_dataclass_transform: Whether to not reset `dataclass_transform_spec` attribute
            of `ModelMetaclass` for testing purposes.
    )init_forbid_extra
init_typedwarn_required_dynamic_aliasesr   r   r   r   r   r   r]   r*   rU   r^   c                   |j         d S t          |j                   }||                    di                               di           }| j        D ]P}|                    |d          }t	          |t
                    st          d|           t          | ||           Qd S t                      }|	                    |j                    | j        D ]0}|
                    t          |d          }t          | ||           1d S )NtoolrI   Fz/Configuration value must be a boolean for key: )fallback)config_file
parse_tomlget	__slots__rs   r   
ValueErrorsetattrr   read
getbooleanCONFIGFILE_KEY)rg   r]   toml_configconfigkeysettingrb   s          rY   rf   zPydanticPluginConfig.__init__  s$   &F !455" __VR0044_bIIF~ , , **S%00!'400 ^$%\WZ%\%\]]]c7++++	, , )NNMw2333~ , ,'22>3QV2WWc7++++, ,r[   r   c                *      fd j         D             S )z/Returns a dict of config names to their values.c                2    i | ]}|t          |          S r   )r   )ro   r   rg   s     rY   
<dictcomp>z0PydanticPluginConfig.to_data.<locals>.<dictcomp>"  s%    BBBCWT3''BBBr[   )r   rg   s   `rY   rc   zPydanticPluginConfig.to_data   s    BBBB4>BBBBr[   Nr   rU   r   )r   r   r   r   r   __annotations__rf   rc   r   r[   rY   ra   ra      s          I ''''####, , , ,&C C C C C Cr[   ra   r   r.   r=   c                \   | j         }t          |t                    r|j        }t          |t                    r"t          |j        t                    r|j        }nMt          |t                    r|}n5d| d|j        j         d}t          || j
        | j                   | j        S |j         j                            t                    }|| j        S |                    di                               d          }|dur%t!          |j         j        | j
        | j                   | j        S )z1Raise an error if from_attributes is not enabled.z
ctx.type: 
 (of type )Nr   from_attributesT)r   rs   r?   itemr9   r   r:   rh   r   error_unexpected_behaviorr   r   r   metadatar   METADATA_KEYerror_from_attributesname)r   ctx_type
model_typedetailpydantic_metadatar   s         rY   r   r   %  s%    xH(H%% !=(L)) 'j9JH.U.U '&

	Hh	'	' '

PhPP(2D2MPPP!&#'3;???&&"044\BB &&'++Hb99==>OPPOd""jo2CGS[III""r[   c                  Z    e Zd ZdZd%dZd&dZd'dZd(dZd)dZe	d*d             Z
d+d#Zd$S ),PydanticModelFieldz5Based on mypy.plugins.dataclasses.DataclassAttribute.r   rT   alias
str | Nonehas_dynamic_aliasr   has_defaultlineintcolumnr   Type | Noner   r(   c	                v    || _         || _        || _        || _        || _        || _        || _        || _        d S r`   )r   r   r   r   r   r   r   r   )	rg   r   r   r   r   r   r   r   r   s	            rY   rf   zPydanticModelField.__init__?  sB     	
!2&					r[   current_infotypedforce_optional	use_aliasrU   r   c                    t          |                     ||          |r|                     |          nt          t          j                  d|s| j        rt          nt                    S )zABased on mypy.plugins.dataclasses.DataclassAttribute.to_argument.N)variabletype_annotationinitializerkind)	r   to_varr	   r8   r>   explicitr   r   r   )rg   r   r   r   r   s        rY   to_argumentzPydanticModelField.to_argumentS  sh    [[y99>CdD,,\:::QZQcIdId"0SD4DS)	
 
 
 	
r[   c                    | j         It          | j        dd          3t          | j         | j        j        j        t          |          i          S | j         S )zABased on mypy.plugins.dataclasses.DataclassAttribute.expand_type.N	self_type)r   r   r   r	   r  idrC   )rg   r   s     rY   r	   zPydanticModelField.expand_type\  sQ     9 WTYT%J%J%V
 ty49+>+A=Q]C^C^*_```yr[   r)   c                x    |r| j         | j         }n| j        }t          ||                     |                    S )z<Based on mypy.plugins.dataclasses.DataclassAttribute.to_var.)r   r   r)   r	   )rg   r   r   r   s       rY   r   zPydanticModelField.to_varg  s?     	/:DD9D4)),77888r[   r   c                    | j         sJ | j        | j        | j        | j        | j        | j        | j                                         dS )z?Based on mypy.plugins.dataclasses.DataclassAttribute.serialize.)r   r   r   r   r   r   r   )r   r   r   r   r   r   r   	serializer   s    rY   r  zPydanticModelField.serializep  sP    yIZ!%!7+IkI''))
 
 	
r[   datar   r1   c                    |                                 }t          |                    d          |          } | d||d|S )zABased on mypy.plugins.dataclasses.DataclassAttribute.deserialize.r   )r   r   r   )copyr3   pop)r   r   r  r   typs        rY   deserializezPydanticModelField.deserialize}  sI     yy{{(&)9)93??s/$//$///r[   sub_typer^   c                X    | j         "t          | j         || j                  | _         dS dS )zxExpands type vars in the context of a subtype when an attribute is inherited
        from a generic super type.
        N)r   r7   r   )rg   r  s     rY   expand_typevar_from_subtypez.PydanticModelField.expand_typevar_from_subtype  s/     9 /	8TYOODIII ! r[   N)r   rT   r   r   r   r   r   r   r   r   r   r   r   r   r   r(   )
r   r(   r   r   r   r   r   r   rU   r   )r   r(   rU   r   )r   r(   r   r   rU   r)   )rU   r   )r   r(   r  r   r   r1   rU   r   )r  r(   rU   r^   )r   r   r   r   rf   r  r	   r   r  classmethodr  r  r   r[   rY   r   r   <  s        ??   (
 
 
 
	 	 	 	9 9 9 9
 
 
 
 0 0 0 [0P P P P P Pr[   r   c                      e Zd ZU dZh dZded<   dCdZdDdZdEdZdFdZ	dGdZ
dHdZdIdZdJd"ZdKd*ZdLd/ZdMd0ZdNd2ZdOd6ZedPd7            ZedQd9            ZdRd>ZdSd?ZedTdA            ZdBS )Ur   zTransform the BaseModel subclass according to the plugin settings.

    Attributes:
        tracked_config_fields: A set of field configs that the plugin has to track their value.
    >   extrafrozenalias_generatorr   populate_by_namezset[str]tracked_config_fieldsr   r   r   Expression | Statementr   r1   rb   ra   rU   r^   c                >    || _         || _        || _        || _        d S r`   )_cls_reason_apirb   )rg   r   r   r   rb   s        rY   rf   z!PydanticModelTransformer.__init__  s'     		*r[   r   c                N   | j         j        }t          d |j        dd         D                       }|                                 }|                     ||          }|dS |D ]}|j         dS t          d |j        dd         D                       }|                     ||||           |                     |||           | 	                    ||j
        du            |                                  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 frozen = True
        * stores the fields, config, and if the class is settings in the mypy metadata for access by subclasses
        c              3  2   K   | ]}t           |j        v V  d S r`   )ROOT_MODEL_FULLNAMEri   rn   s     rY   rq   z5PydanticModelTransformer.transform.<locals>.<genexpr>  s*      [[T/4=@[[[[[[r[   NFc              3  6   K   | ]}|j         t          k    V  d S r`   )ri   BASESETTINGS_FULLNAMErn   s     rY   rq   z5PydanticModelTransformer.transform.<locals>.<genexpr>  s*      [[T$-+@@[[[[[[r[   T)r  c                B    i | ]}|j         |                                S r   )r   r  )ro   fields     rY   r   z6PydanticModelTransformer.transform.<locals>.<dictcomp>  s&    IIIuz5??#4#4IIIr[   )fieldsr   )r  r   ru   rv   collect_configcollect_fieldsr   add_initializeradd_model_construct_method
set_frozenr  adjust_decorator_signaturesget_values_dictr   r   )rg   r   is_root_modelr   r%  r$  is_settingss          rY   r   z"PydanticModelTransformer.transform  sR    y~[[TXVYWYVY][[[[[$$&&$$V];;>5 	 	Ez!uu " [[TXVYWYVY][[[[[VV[-HHH''DDDv}'<===((*** JI&III,,..'
 '
l#
 tr[   c                   | j         j        j                                        D ]\  }}t	          |j        t                    r|j        j        d         t	          t                    rt	          j	        t                    rfj	        j        t          v rSj	        j        t          k    r-t          fdt          j                  D                       sd|j        j        _        dS )a  When we decorate a function `f` with `pydantic.validator(...)`, `pydantic.field_validator`
        or `pydantic.serializer(...)`, 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()`,
        `field_validator()` or `serializer()` call as a `classmethod`.
        r   c              3     K   | ]8\  }}j         |         d k    ot          |t                    o
|j        dk    V  9dS )modeafterN)	arg_namesrs   r$   value)ro   ir   	first_decs      rY   rq   zGPydanticModelTransformer.adjust_decorator_signatures.<locals>.<genexpr>  sg           &3 &/2f<rCQXAYAYr^a^gkr^r           r[   TN)r  r   namesr   rs   rt   r   original_decoratorsr   calleer   ri   DECORATOR_FULLNAMESMODEL_VALIDATOR_FULLNAMEru   	enumerater   funcis_class)rg   r   ry   r6  s      @rY   r+  z4PydanticModelTransformer.adjust_decorator_signatures  s     -3355 	2 	2ID##(I.. 2H8;	y(332"9#3X>>2 "(15HHH "(15MMM        *3IN*C*C        N .2CHM*#	2 	2r[   ModelConfigDatac                   | j         }t                      }d}d}|j                                        D ]4\  }}|                     ||          }|rd}|                    |           5d}|j        j        D ]}t          |t          t          f          s t          |t                    r|j        d         }	t          |	t                    r|	j        dk    rdt          |j        t                    rXt!          |j        j        |j        j                  D ]1\  }
}|
|                    |                     |
|                     2nt          |j        t&                    rV|j        j        D ]I\  }}t          |t(                    s|                    |                     |j        |                     Jnt          |t                    r|j        dk    ri|j        j        D ]n}t          |t                    s|j        d         }	t          |	t                    s;|                    |                     |	j        |j                             o|r| j                            d|            nd}|s|r1|r/|j        r(|j        s!| j        j        rt9          | j        |           |j        j        dd         D ]}t>          |j         vr| j        !                    tE          |j#                             |j         t>                   d	                                         D ]\  }}|$                    ||           |S )
zhCollects the values of the config attributes that are used by the plugin, accounting for parent classes.FTNr   model_configConfigzYSpecifying config in two places is ambiguous, use either Config attribute or class kwargsr   r   )%r  r?  keywordsr   get_config_updateupdatedefsbodyrs   r   r   lvaluesr   r   rvaluer   zipr3  r   r   r$   r4  r  failhas_alias_generatorr  rb   r   error_required_dynamic_aliasesr   rv   r   r   add_plugin_dependencyr5   ri   
setdefault)rg   r   r   has_config_kwargshas_config_from_namespacer   exprconfig_datastmtlhsarg_namer   key_expr
value_exprsubstmtr   r4  s                    rY   r&  z'PydanticModelTransformer.collect_config  s   i ""!$)! ,,,.. 	+ 	+JD$00t<<K +$(!k*** "&HM &	- &	-Dd^X$>?? $// Tl1o!#x00 CH4N4Ndk844 	Z),T[-BDKDT)U)U M M##+$d&<&<Xs&K&KLLLLM  X66 Z040A Z Z,*)(G<< %$d&<&<X^Z&X&XYYYYD(++ 	T9((#y~ T TG%g~>> ! !/!,C%c844 ! MM$"8"87>"R"RSSSS  	o   (,%% 	@ 9 	@@.@ /@ &D	@ /ty$???HL$ 	/ 	/D4=00 I++,A$-,P,PQQQ#}\:8DJJLL / /e!!$..../r[   rA  r-  list[PydanticModelField] | Nonec                `   | j         }i }t          |j        j        dd                   D ]K}t          |j        vr| j                            t          |j	                             |j        t                   d         
                                D ]\  }}t                              ||| j                  }t          j        | j        j        j                  5  |                    |j                   ddd           n# 1 swxY w Y   |||<   |j        j                            |          }	|	rA|	j        r:t+          |	j        t,                    s | j                            d|	j                   Mt1                      }
|                     |j                  D ]n}|                     ||          }|T|j        d         }|r!|j        dk    rt=          | j        |           J|
                    |j                   |||j        <   otA          |!                                          S )zACollects the fields for the model, accounting for parent classes.r   r   r%  Nz7BaseModel field may only be overridden by another fieldr   root)"r  reversedr   rv   r   r   r  rN  r5   ri   r   r   r  r6   strict_optional_setr]   strict_optionalr  r7  r   rt   rs   r)   rK  set%_get_assignment_statements_from_blockrF  collect_field_from_stmtrH  r    error_extra_fields_on_root_modeladdlistvalues)rg   rA  r-  r   found_fieldsr   r   r  r$  sym_nodecurrent_field_namesrT  maybe_fieldrU  s                 rY   r'  z'PydanticModelTransformer.collect_fields2  sg   i 79SX\!B$/00 	 	D 4=00 I++,A$-,P,PQQQ"mL9(CIIKK  
d*66tT49MM
 .ty/@/PQQ @ @55ch???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @%*T"8>--d33  jPS6T6T INNQ   $ ),>>sxHH 	9 	9D66t\JJK&l1o  9SX%7%74TYEEEE'++CH555-8L*L''))***s   DD
DrT  r   Iterator[AssignmentStmt]c              #     K   |j         D ]$}|j        s|                     |          E d {V  %|j        .|j        j        s$|                     |j                  E d {V  d S d S d S r`   )rG  is_unreachablera  	else_body)rg   rT  rG  s      rY   ,_get_assignment_statements_from_if_statementzEPydanticModelTransformer._get_assignment_statements_from_if_statementi  s      I 	L 	LD& LEEdKKKKKKKKK>%dn.K%AA$.QQQQQQQQQQQ &%%%r[   blockr   c              #     K   |j         D ]L}t          |t                    r|V  t          |t                    r|                     |          E d {V  Md S r`   )rG  rs   r   r   ro  )rg   rp  rT  s      rY   ra  z>PydanticModelTransformer._get_assignment_statements_from_blockp  s}      J 	S 	SD$// S



D&)) SLLTRRRRRRRRR		S 	Sr[   r   PydanticModelField | Nonec           
     n   | j         }|j        d         }t          |t                    r$t	          j        |j                  r|j        dk    rdS |j        st          |j        t                    rbt          |j        j
        t                    rCt          |j        j
        j
        t                    r|j        j
        j
        j        t          v rdS t          | j        |           dS |j        d         }t          |t                    sdS t	          j        |j                  r|j        dk    rdS |j        j                            |j                  }|dS |j        }t          |t&                    rdS t          |t(                    r| j                            d|           dS t          |t,                    sdS |j        rdS t1          |j                  }t          |t4                    r+|j        j        dk    r| j                            d|           |                     |          }|j        r|j        rk|j        rd| j                            |j        d          }	|	r|	|_        n9| j                            d	|           t?          t@          j!                  |_        | "                    |          \  }
}|r(|j#        s!| j$        j%        rtM          | j        |           | '                    ||j        |          }tQ          |j        |||
|j)        |j*        ||j        
          S )a  Get pydantic model field from statement.

        Args:
            stmt: The statement.
            model_config: Configuration settings for the model.

        Returns:
            A pydantic model field if it could find the field in statement. Otherwise, `None`.
        r   rA  NzFType aliases inside BaseModel definitions are not supported at runtimezdataclasses.InitVarz%InitVar is not supported in BaseModelT)is_finalzGNeed type argument for Final[...] with non-literal default in BaseModel)r   r   r   r   r   r   r   r   )+r  rH  rs   r   rF   is_valid_field_namer   
new_syntaxrI  r   r9  ri   r:  error_untyped_fieldsr  r   r7  r   rt   r!   r'   rK  r)   is_classvarrB   r   r:   get_has_defaultrt  is_inferredanalyze_simple_literal_typer8   r>   
from_errorget_alias_infor  rb   r   rM  _infer_dataclass_attr_init_typer   r   r   )rg   rT  rA  r   rU  ry   rt   	node_typer   r  r   r   	init_types                rY   rb  z0PydanticModelTransformer.collect_field_from_stmtw  sA    il1o#x(( 	0KCH0U0U 	Y\YaesYsYs4 	4;11	t{18<<	 t{18(CC	 K&-6:MMM
 t !D1114l1o#x(( 	4*3844 	N8R8R4hn  **; 4xdO,, 	
 4dI&& 	INNX   4$$$ 	
 4  	4 $DI..	i** 	y~/FJ_/_/_INN7  
 **4008$2B )77d7SSC :			]   $I$899	#'#6#6t#<#<   	<\%B 	<tGYGw 	<*49d;;;88chMM	!/#;	
 	
 	
 		
r[   ry   r%   r   rT   r   r   r   c                   |j         }|j        r|S t          |j                   }t          |t                    s|S |j                             d          }|r!t          |j        t                    r|j                             d          }|sJ |j         r)t          t          |j         |j         |                    }nt          t          j                  S t          |t                    r8|j        t          t          t          gk    rt!          |j        d         |          S | j                            d|j         j         d|           n)| j                            d|j         j         d|           |S )zvInfer __init__ argument type for an attribute.

        In particular, possibly use the signature of __set__.
        __set__rR   z(Unsupported signature for "__set__" in ""zUnsupported "__set__" in ")r   implicitrB   rs   r:   r   rt   r   get_containing_type_infor7   r8   r>   unannotatedr9   	arg_kindsr   r
   r   r  rK  r   )	rg   ry   r   r   r   tsetter
super_infosetter_types	            rY   r~  z8PydanticModelTransformer._infer_dataclass_attr_init_type  sr   
 (< 	NCH%% !X&& 	NI&& 	U&+w// UV<<YGG
!!!!; :"12I&+WXW]_i2j2j"k"kKK"9#8999k<88 g[=RW > >
 3;3H3KQOOOINN#\afk#\#\#\^effff	JAFKJJJGTTTr[   r%  list[PydanticModelField]r   r.  c           
        d| j         j        j        v r| j         j        j        d         j        sdS | j        j        }|j        du}t          |j        o|j                   }t          j
        | j        j        j                  5  |                     |||||          }|r/|d         j        t           k    rt"          nt$          |d         _        |r| j                            t(                    j        }	d|	j        v r|	j        d         j        }
|
|
j        |
j        }t/          |j                  D ]\  }}|                    d          s|                    d          s0| j                            |j        |                   }t9          ||          }|                    t=          ||dt$                               ddd           n# 1 swxY w Y   |                     ||          sPt9          d          }|                    t=          |tA          tB          j"                  dtF                               tI          | j        | j         d|tK                      	           dS )
zAdds a fields-aware `__init__` method to the class.

        The added `__init__` will be annotated with types vs. all `Any` depending on the plugin settings.
        rf   NTr   requires_dynamic_aliasesr   r.  r   __r   kwargs)r   return_type)&r  r   r7  plugin_generatedrb   r   r  r   rL  r6   r^  r  r]   r_  get_field_argumentsr   r   r   r   rr   r"  rt   r   r<  r3  
startswith	anal_typer   r)   appendr   should_init_forbid_extrar8   r>   r   r   
add_methodr;   )rg   r%  r   r.  r-  r   r   r  r   base_settings_nodebase_settings_init_node	func_typearg_idxrV  analyzed_variable_typer   vars                    rY   r(  z(PydanticModelTransformer.add_initializer  s    ---din6J:6V6g-F"-+47	#'(B(b6KbGb#c#c &ty'8'HII 	c 	c++)A#' ,  D  Q*.q',)*C*CwwQ c%)Y%E%EF[%\%\%a"!3!999.@.Fz.R.W+.:?V?[?g$;$@	1:9;N1O1O c c-GX'22488 )@S@STW@X@X ) (59Y5H5HI\]dIe5f5f2'*85K'L'LH KK;QSWY`(a(abbbb/	c 	c 	c 	c 	c 	c 	c 	c 	c 	c 	c 	c 	c 	c 	c2 ,,VV<< 	Uh--CKKgi.@&A&A4SSTTT49di$HJJWWWWWWs   EGGGc           	         | j                             t           d| j                             t           d          g          }t          |t	                      g          }t          t          d|          |dt                    }t          j	        | j         j
        j                  5  |                     |ddd|          }ddd           n# 1 swxY w Y   |                     ||          sPt          d          }|                    t          |t          t           j                  dt$                               |g|z   }t'          | j         | j        d	|t+          | j        j                  d
           dS )zAdds a fully typed `model_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.str_fields_setNTFr  r  model_construct)r   r  is_classmethod)r  
named_typeBUILTINS_NAMErA   r;   r   r)   r   r6   r^  r]   r_  r  r  r  r8   r>   r   r   r  r  rC   r   )	rg   r%  r   r.  set_stroptional_set_strfields_set_argumentr   r  s	            rY   r)  z3PydanticModelTransformer.add_model_construct_methodA  s    )&&-'='='=	@T@TXeUkUkUk@l@l?mnn$gxzz%:;;&s=:J'K'KM]_celmm&ty'8'HII 	 	++dUeal ,  D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ,,VV<< 	Uh--CKKgi.@&A&A4SSTTT#$t+II%din55	
 	
 	
 	
 	
 	
s   *CCCr  c                   | j         j        }|D ];}|j                            |j                  }||j        }t          |t                    r||_        Ht          |t                    r&| j
        j        s| j
                                         	 t          |          }n# t          $ r t          |          }Y nw xY wd| d|j         d}t#          || j
        | j                    |                    |d          }||_        ||_        |j        dz   |j        z   |_        t+          t,          |          |j        |j        <   =dS )zMarks 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   .)r  r   r7  r   r   rt   rs   r)   is_propertyr!   r  final_iterationdeferrT   	TypeErrorreprrh   r   r   ri   	_fullnamer%   r   )	rg   r%  r  r   r$  rh  r  var_strr   s	            rY   r*  z#PydanticModelTransformer.set_frozen_  sb   
 y~ 	B 	BEz~~ej11H#mc3'' L&,COO_55 Ldi>W LIOO%%%%,"%c(($ , , ,"&s)), SwRR#-RRRF-fdiKKKKll45l99"( $ 3ch >'6tS'A'A
38$$/	B 	Bs   B##B?>B?r   r   ModelConfigData | Nonec                   || j         vrdS |dk    rjt          |t                    r|j        dk    }n9t          |t                    r|j        dk    }nt          || j        |           dS t          |          S |dk    r4d}t          |t                    r|j
        dk    rd}t          |	          S t          |t                    r |j
        d
v rt          di ||j
        dk    iS t          || j        |           dS )zDetermines the config update due to a single kwarg in the ConfigDict definition.

        Warns if a tracked config attribute is set to a value the plugin doesn't know how to interpret (e.g., an int)
        Nr  forbid)forbid_extrar  Tbuiltins.NoneF)rL  )builtins.Truezbuiltins.Falser  r   )r  rs   r$   r4  r   r   error_invalid_config_valuer  r?  r   ri   )rg   r   r   r  rL  s        rY   rD  z*PydanticModelTransformer.get_config_update~  s+   
 t11147??#w'' "yH4C,, "x83*4C@@@t"====$$$"&#x(( ,S\_-L-L&+#"7JKKKKc8$$ 	N9\)\)\"MMdCLO,K%LMMM"4C888tr[   c                   | j         }t          |t                    rdS t          |t                    rt          |j        t
                    rx|j        j        t          k    rct          |j	        |j
                  D ]F\  }}||dk    r|j        t          uc S |dk    r#t          |t                    o
|j        dk     c S GdS t          |t                     S )zUReturns a boolean indicating whether the field defined in `stmt` is a required field.FNr   r   r  )rI  rs   r&   r   r9  r"   ri   r   rJ  r   r3  rh   r   r   )rT  rR  r   r   s       rY   ry  z(PydanticModelTransformer.get_has_default  s     {dH%% 	5dH%% 	*T['*J*J 	t{OcguOuOu
 !DN;; _ _	T<49#4#4=<<<<,,, *3 9 9 ]clo>]^^^^ -5dL1111r[   tuple[str | None, bool]c                n   | 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|j
        |         }t          |t                    r|j        dfc 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)rI  rs   r&   r   r9  r"   ri   r   r<  r3  r   r$   r4  )rT  rR  r5  rV  r   s        rY   r}  z'PydanticModelTransformer.get_alias_info  s     {dH%% 	; tX&&	+5dk7+K+K	PTP[PdhvPvPv ;$T^44 	" 	"KAx7"")A,C#w'' "y%''''!zz{r[   r   r   r  list[Argument]c                L    | j         j        fd|D             }|S )zHelper function used during the construction of the `__init__` and `model_construct` method signatures.

        Returns a list of mypy Argument instances for use in the generated signatures.
        c                X    g | ]&}r|j         |                    p           'S ))r   r   r   )r   r  )ro   r$  r   r.  r  r   r   s     rY   
<listcomp>z@PydanticModelTransformer.get_field_arguments.<locals>.<listcomp>  sc     
 
 
 

 #("9
E2J2Yken   
 
 
r[   )r  r   )rg   r%  r   r   r  r.  	argumentsr   s     ```` @rY   r  z,PydanticModelTransformer.get_field_arguments  sX     y~
 
 
 
 
 
 
 
  	
 
 
	 r[   c                    |j         s*|                     |t          |j                            rdS |j        rdS | j        j        S )a@  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   rL  r  rb   r   )rg   r%  r   s      rY   r  z1PydanticModelTransformer.should_init_forbid_extra  sS     & 	,,VT&:T5U5UVV u 	4!33r[   rL  c                F    | D ]}|j         r dS |r| D ]}|j         dS dS )zReturns 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%  rL  r$  s      rY   r  z1PydanticModelTransformer.is_dynamic_alias_present  sZ    
  	 	E& tt 	     ;&44 'ur[   N)
r   r   r   r  r   r1   rb   ra   rU   r^   )rU   r   )rU   r^   )rU   r?  )rA  r?  r-  r   rU   rZ  )rT  r   rU   rk  )rp  r   rU   rk  )rT  r   rA  r?  rU   rr  )ry   r%   r   rT   r   r   rU   r   )
r%  r  r   r?  r.  r   r-  r   rU   r^   )r%  r  r   r?  r.  r   rU   r^   )r%  r  r  r   rU   r^   )r   rT   r   r   rU   r  )rT  r   rU   r   )rT  r   rU   r  )r%  r  r   r   r   r   r  r   r.  r   rU   r  )r%  r  r   r?  rU   r   )r%  r  rL  r   rU   r   )r   r   r   r   r  r   rf   r   r+  r&  r'  ro  ra  rb  r~  r(  r)  r*  rD  staticmethodry  r}  r  r  r  r   r[   rY   r   r     s         ' ' '    + + + +! ! ! !F2 2 2 26J J J JX5+ 5+ 5+ 5+nR R R RS S S Sv
 v
 v
 v
p$ $ $ $L*X *X *X *XX
 
 
 
<B B B B>   4 2 2 2 \2*    \6   ,4 4 4 4    \  r[   r   c                  >    e Zd ZdZ	 	 	 	 	 ddd	ZddZddZddZdS )r?  z(Pydantic mypy plugin model config class.Nr  bool | Noner  r   r  rL  c                L    || _         || _        || _        || _        || _        d S r`   )r  r  r   r  rL  )rg   r  r  r   r  rL  s         rY   rf   zModelConfigData.__init__  s1     ). 0#6   r[   rU   r   c                H    d | j                                         D             S )zReturns a dict of Pydantic model config names to their values.

        It includes the config if config value is not `None`.
        c                    i | ]
\  }}|||S r`   r   )ro   kvs      rY   r   z3ModelConfigData.get_values_dict.<locals>.<dictcomp>  s    HHHA!-1---r[   )__dict__r   r   s    rY   r,  zModelConfigData.get_values_dict  s'    
 IH!4!4!6!6HHHHr[   r   r  r^   c                    |dS |                                                                 D ]\  }}t          | ||           dS )z$Update Pydantic model config values.N)r,  r   r   )rg   r   r  r  s       rY   rE  zModelConfigData.update  sV    >F**,,2244 	  	 DAqD!Q	  	 r[   r   rT   r4  r   c                L    t          | |          t          | ||           dS dS )zFSet default value for Pydantic model config if config value is `None`.N)r   r   )rg   r   r4  s      rY   rO  zModelConfigData.setdefault  s2    4%D#u%%%%% &%r[   )NNNNN)
r  r  r  r  r   r  r  r  rL  r  r   )r   r  rU   r^   )r   rT   r4  r   rU   r^   )r   r   r   r   rf   r,  rE  rO  r   r[   rY   r?  r?    s        22 %)"'+(,+/7 7 7 7 7I I I I       & & & & & &r[   r?  zpydantic-ormzInvalid from_attributes callPydanticzpydantic-configzInvalid config valuezpydantic-aliaszDynamic alias disallowedzpydantic-unexpectedzUnexpected behaviorzpydantic-fieldzUntyped field disallowedzInvalid Field defaultsz!Extra field on RootModel subclass
model_namer   r+   r   r   r^   c                H    |                     d|  d|t                     dS )zCEmits an error when the model does not have `from_attributes=True`.r  z$" does not have from_attributes=TruecodeN)rK  	ERROR_ORM)r  r   r   s      rY   r   r   *  s-    HHAAAA7QZH[[[[[r[   r   r1   c                H    |                     d|  d|t                     dS )z0Emits an error when the config value is invalid.zInvalid value for "Config.r  r  N)rK  ERROR_CONFIG)r   r   r   s      rY   r  r  /  s,    HH1$1117HNNNNNr[   c                @    |                      d|t                     dS )znEmits required dynamic aliases error.

    This will be called when `warn_required_dynamic_aliases=True`.
    z#Required dynamic aliases disallowedr  N)rK  ERROR_ALIASr   r   s     rY   rM  rM  4  s#    
 HH2G+HNNNNNr[   r   8CheckerPluginInterface | SemanticAnalyzerPluginInterfacec                b    d}d|  d}|d| dz  }|                     ||t                     dS )z Emits unexpected behavior error.z6https://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!r  N)rK  ERROR_UNEXPECTED)r   r   r   linkfull_messages        rY   r   r   <  sO    
 DDWVWWWL\T\\\\LHH\7)9H:::::r[   c                @    |                      d|t                     dS )z;Emits an error when there is an untyped field in the model.zUntyped fields disallowedr  N)rK  ERROR_UNTYPEDr  s     rY   rw  rw  G  s!    HH('HFFFFFr[   c                @    |                      d|t                     dS )z]Emits an error when there is more than just a root field defined for a subclass of RootModel.z2Only `root` is allowed as a field of a `RootModel`r  N)rK  ERROR_EXTRA_FIELD_ROOT_MODELr  s     rY   rc  rc  L  s"    HHA7QmHnnnnnr[   c                @    |                      d|t                     dS )zNEmits an error when `Field` has both `default` and `default_factory` together.z>Field default and default_factory cannot be specified togetherr  N)rK  ERROR_FIELD_DEFAULTSr  s     rY   r   r   Q  s"    HHMw]qHrrrrrr[   F8SemanticAnalyzerPluginInterface | CheckerPluginInterfacer   r   r   r  r  r  r   tvar_defTypeVarDef | Noner  r   c                ,   |j         }||j        v rR|j        |         }	|	j        r>t          |	j        t
                    r$|j        j                            |	j                   t          | t                    r| 
                    d          }
n|                     dg           }
|rE|pt          t          |                    }t          t          d          |dt           d          g}n6|pt          |          }t          t          d          |dt                     g}||z   }g g g }}}|D ]f}|j        s
J d            |                    |j                   |                    |j        j                   |                    |j                   gt-          |||||
          }|r|g|_        t          ||t1          t3                      g                    }||_         t5          ||          |_        ||_        |j        dz   |z   |_        |j        |_        ||j        v r*tA          ||j                  }|j        |         |j        |<   |rwd|_!        t          ||j                  }||_         |j        |_        d|_"        tG          |tI          d          g|          }|j        |_        tK          tL          |          }	ntK          tL          |          }	d|	_        |	|j        |<   |j'        j        j                            |           dS )	zhVery closely related to `mypy.plugins.common.add_method_to_class`, with a few pydantic-specific changes.zbuiltins.functionr  NT__pydantic_self__z"All arguments must be fully typed.r  r  )(r   r7  r  rs   rt   r   rF  rG  remover1   r  named_generic_typer?   rC   r   r)   r   r   r  r   r   r   r9   	variablesr   r    r4   r   r>  ri   r  r   rD   is_decoratedr  r   r   r%   r   defn)r   r   r   r   r  r  r  r  r   ry   function_typefirstr   r3  r  r   	signaturer=  r_namer  decs                        rY   r  r  V  s    8D tzj 	+Jsx$A$A 	+HM  ***#677 H':;;../BBGG O>-*=*=!>!>	#f++y$FFG4t!4!4	#122ItWMMN4<D&("b)yI # #"HH$HHHH,---*+++""""Y	9k=YYI )'j	4uhjj\2233DDI!)T22DI"DM]S(4/DN	DI tz-dDJ??!Z-
6
  
* di  nx667;;9dC((dD))CDJtINt$$$$$r[   r   dict[str, Any] | Nonec                8   |                      d          sdS t          j        dk    rddl}n0	 ddl}n*# t
          $ r ddl}|                    d           Y dS w xY wt          | d          5 }|	                    |          cddd           S # 1 swxY w Y   dS )zReturns a dict of config keys to values.

    It reads configs from toml file and returns `None` if the file is not a toml file.
    z.tomlN)      r   zJNo TOML parser installed, cannot read configuration from `pyproject.toml`.rb)
r   sysversion_infotomllibtomliImportErrorwarningswarnopenload)r   toml_r  rfs       rY   r   r     s   
 (( t
7""	!!!!! 	 	 	OOOMMfggg44		 
k4	 	  Bzz"~~                 s!   3 #AA-BBB)rS   rT   rU   rV   )r   r.   rU   r=   )r  rT   r   r+   r   r   rU   r^   )r   rT   r   r1   r   r   rU   r^   )r   r1   r   r   rU   r^   )r   rT   r   r  r   r   rU   r^   )r   r+   r   r   rU   r^   )NNF)r   r  r   r   r   rT   r   r  r  r=   r  r   r  r  r  r   rU   r^   )r   rT   rU   r  )r   
__future__r   r  configparserr   typingr   r   r   mypy.errorcodesr   mypy.expandtyper	   r
   
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'   r(   r)   mypy.optionsr*   mypy.pluginr+   r,   r-   r.   r/   r0   r1   mypy.pluginsr2   mypy.plugins.commonr3   mypy.semanalr4   mypy.server.triggerr5   
mypy.stater6   mypy.typeopsr7   
mypy.typesr8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   mypy.typevarsrC   	mypy.utilrD   mypy.versionrE   mypy_versionpydantic._internalrF   pydantic.versionrG   rH   r  r   r   rm   r"  r  r}   r   r   r;  r:  r   r  rZ   rX   ra   r   r   r   r?  r  r  r  r  r  r  r  r   r  rM  r   rw  rc  r   r  r   r   r[   rY   <module>r     s   d d " " " " " " 



 % % % % % % * * * * * * * * * * % % % % % % @ @ @ @ @ @ @ @                                                                                                                                   B !                            % $ $ $ $ $      + * * * * * 5 5 5 5 5 5       0 0 0 0 0 0                          ( ' ' ' ' ' 2 2 2 2 2 2 4 4 4 4 4 4 & & & & & & / / / / / /5%%%%%%% 5 5 5444444445 !'. = 5 R (5 K     ('55 0H<<

.    s  s  s  s  s V s  s  s l+C +C +C +C +C +C +C +C\# # # #.MP MP MP MP MP MP MP MP`m	 m	 m	 m	 m	 m	 m	 m	`"& "& "& "& "& "& "& "&J In&DjQQ	y*,BJOOi(*DjQQ924I:VV 	*,F
SS y!13KZXX (y)9;^`jkk \ \ \ \
O O O O
O O O O; ; ; ;G G G G
o o o o
s s s s ""& K% K% K% K% K%\     s   "C) )C76C7