HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //proc/1233/root/usr/local/lib/python3.10/dist-packages/pydantic/__pycache__/mypy.cpython-310.pyc
o

|��g.��@sdZddlmZddlZddlmZddlmZmZm	Z	ddl
mZddlm
Z
mZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm 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/dd	l0m1Z1dd
l2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8ddl9m:Z:ddl;m<Z<dd
l=m>Z>ddl?m@Z@ddlAmBZBddlCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMddlNmOZOddlPmQZQddlRmSZTddlUmVZVddlWmXZXdZYdZZdZ[dZ\dZ]dZ^dZ_dZ`dZahd�ZbeXeT�Zcd Zdd!ZSdod&d'�ZeGd(d)�d)e6�ZfGd*d+�d+�Zgdpd/d0�ZhGd1d2�d2�ZiGd3d4�d4�ZjGd5d6�d6�ZkGd7d8�d8�Zled9d:d;�Zmed<d=d;�Zned>d?d;�Zoed@dAd;�ZpedBdCd;�ZqedBdDd;�ZredBdEd;�ZsdqdLdM�ZtdrdPdQ�ZudsdRdS�ZvdtdVdW�ZwdsdXdY�ZxdudZd[�Zy			\dvdwdidj�Zzdxdmdn�Z{dS)yz^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�	INVARIANT�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�
MethodContext�Plugin�ReportConfigContext�SemanticAnalyzerPluginInterface)�deserialize_and_fixup_type)�set_callable_name)�make_wildcard_trigger)�state)�map_type_from_supertype)
�AnyType�CallableType�Instance�NoneType�Type�	TypeOfAny�TypeType�TypeVarType�	UnionType�get_proper_type)�
fill_typevars)�get_unique_redefinition_name)�__version__)�_fields)�parse_mypy_version�
pydantic-mypyzpydantic-mypy-metadatazpydantic.main.BaseModelz#pydantic_settings.main.BaseSettingszpydantic.root_model.RootModelz5pydantic._internal._model_construction.ModelMetaclasszpydantic.fields.Fieldzpydantic.dataclasses.dataclass�.pydantic.functional_validators.model_validator>�*pydantic.functional_serializers.serializer�.pydantic.deprecated.class_validators.validator�.pydantic.functional_validators.field_validator�0pydantic.functional_serializers.model_serializer�3pydantic.deprecated.class_validators.root_validatorrF�builtins��version�str�return�type[Plugin]cCstS)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)rN�rS�8/usr/local/lib/python3.10/dist-packages/pydantic/mypy.py�pluginjsrUcs^eZdZdZd�fdd�Zddd�Zdd
d�Zddd�Zddd�Zd dd�Z	d dd�Z
�ZS)!rRzThe Pydantic mypy plugin.�optionsr*rP�Nonecs&t|�|_|j��|_t��|�dS�N)�PydanticPluginConfig�
plugin_config�to_data�_plugin_data�super�__init__)�selfrV��	__class__rSrTr^|s
zPydanticPlugin.__init__�fullnamerO�(Callable[[ClassDefContext], None] | NonecCs:|�|�}|rt|jt�rtdd�|jjD��r|jSdS)zUpdate Pydantic model class.cs��|]}|jtkVqdSrX�rb�BASEMODEL_FULLNAME��.0�baserSrSrT�	<genexpr>���z5PydanticPlugin.get_base_class_hook.<locals>.<genexpr>N)�lookup_fully_qualified�
isinstance�noder(�any�mro�$_pydantic_model_class_maker_callback)r_rb�symrSrSrT�get_base_class_hook�s

z"PydanticPlugin.get_base_class_hookcCs|tkr|jSdS)z,Update Pydantic `ModelMetaclass` definition.N)�MODEL_METACLASS_FULLNAME�)_pydantic_model_metaclass_marker_callback�r_rbrSrSrT�get_metaclass_hook�sz!PydanticPlugin.get_metaclass_hook�&Callable[[MethodContext], Type] | NonecCs|�d�rtSdS)z-Adjust return type of `from_orm` method call.z	.from_ormN)�endswith�from_attributes_callbackrvrSrSrT�get_method_hook�s
zPydanticPlugin.get_method_hook�ctxr/�dict[str, Any]cCs|jS)zjReturn all plugin config data.

        Used by mypy to determine if cache needs to be discarded.
        )r\)r_r|rSrSrT�report_config_data�sz!PydanticPlugin.report_config_datar,cCs"t|j|j|j|j�}|��dSrX)�PydanticModelTransformer�cls�reason�apirZ�	transform)r_r|�transformerrSrSrTrq�sz3PydanticPlugin._pydantic_model_class_maker_callbackcCs@|jjrdS|jjj}|sJd��t|jdd�rd|j_dSdS)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)rZ�debug_dataclass_transformr��info�declared_metaclass�getattr�typer�)r_r|�info_metaclassrSrSrTru�s
�z8PydanticPlugin._pydantic_model_metaclass_marker_callback�rVr*rPrW)rbrOrPrc)rbrOrPrx)r|r/rPr})r|r,rPrW)�__name__�
__module__�__qualname__�__doc__r^rsrwr{r~rqru�
__classcell__rSrSr`rTrRys

	


rRc@sJeZdZUdZdZded<ded<ded<ded<ddd
�Zddd�ZdS)rYa�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��boolr�r�r�r�rVr*rPrWcCs�|jdurdSt|j�}|dur:|�di��di�}|jD]}|�|d�}t|t�s1td|����t|||�qdSt�}|�	|j�|jD]}|j
t|dd�}t|||�qFdS)N�toolrEFz/Configuration value must be a boolean for key: )�fallback)�config_file�
parse_toml�get�	__slots__rmr��
ValueError�setattrr�read�
getboolean�CONFIGFILE_KEY)r_rV�toml_config�config�key�settingrZrSrSrTr^�s"



�
�zPydanticPluginConfig.__init__r}cs�fdd��jD�S)z/Returns a dict of config names to their values.csi|]}|t�|��qSrS)r�)rhr��r_rSrT�
<dictcomp>��z0PydanticPluginConfig.to_data.<locals>.<dictcomp>)r�r�rSr�rTr[��zPydanticPluginConfig.to_dataNr��rPr})r�r�r�r�r��__annotations__r^r[rSrSrSrTrY�s


rYr|r-r:cCs�|j}t|t�r|j}t|t�rt|jt�r|j}nt|t�r"|}nd|�d|jj�d�}t	||j
|j�|jS|jj
�t�}|durF|jStdd�|jjD��sT|jS|�di��d�}|d	urkt|jj|j
|j�|jS)
z1Raise an error if from_attributes is not enabled.z
ctx.type: �
 (of type �)NcsrdrXrergrSrSrTrj�rkz+from_attributes_callback.<locals>.<genexpr>r��from_attributesT)r�rmr<�itemr7�ret_typer8rar��error_unexpected_behaviorr��context�default_return_type�metadatar��METADATA_KEYrorp�error_from_attributes�name)r|�ctx_type�
model_type�detail�pydantic_metadatar�rSrSrTrz�s&

rzc@sbeZdZdZd3dd�Zd4d d!�Z	"d5d6d#d$�Z	"d5d7d&d'�Zd8d)d*�Ze	d9d,d-��Z
d:d0d1�Zd2S);�PydanticModelFieldz5Based on mypy.plugins.dataclasses.DataclassAttribute.r�rO�alias�
str | None�	is_frozenr��has_dynamic_alias�has_default�strict�bool | None�line�int�columnr��Type | Noner�r(cCs@||_||_||_||_||_||_||_||_|	|_|
|_	dSrX)
r�r�r�r�r�r�r�r�r�r�)r_r�r�r�r�r�r�r�r�r�r�rSrSrTr^�s

zPydanticModelField.__init__�current_info�typed�model_strict�force_optional�	use_aliasr�r0�force_typevars_invariant�is_root_model_rootrPrc	Csr|�||||�}	|jdur|n|j}
|s|
r|�||�}nttj�}t|	|d|r,td�S|s1|jr5t	d�St
d�S)zABased on mypy.plugins.dataclasses.DataclassAttribute.to_argument.N)�variable�type_annotation�initializer�kind)�to_varr�rr6r;�explicitrrr�rr
)r_r�r�r�r�r�r�r�r�r�r�r�rSrSrT�to_arguments 
����zPydanticModelField.to_argumentFcCs�|rt|jt�r|j��}t|_||_|jdur[|jjdur[t�	|j
j��.t|�}t|t
�s1J�|rA|jD]
}t|t�r@t|_q6t|j|jjj|i�Wd�S1sVwY|jS)zABased on mypy.plugins.dataclasses.DataclassAttribute.expand_type.N)rmr�r=�
copy_modifiedr�variancer��	self_typer4�strict_optional_setrV�strict_optionalr@r8�argsr�id)r_r�r�r��
modified_type�filled_with_typevars�argrSrSrTr/s"


� �	zPydanticModelField.expand_typer)cCs0|r|jdur|j}n|j}t||�|||��S)z<Based on mypy.plugins.dataclasses.DataclassAttribute.to_var.N)r�r�r)r)r_r�r�r�r�r�rSrSrTr�MszPydanticModelField.to_varrc
Cs8|jsJ�|j|j|j|j|j|j|j|j|j�	�d�	S)�?Based on mypy.plugins.dataclasses.DataclassAttribute.serialize.)	r�r�r�r�r�r�r�r�r�)
r�r�r�r�r�r�r�r�r��	serializer�rSrSrTr�\s
�zPydanticModelField.serialize�datacCs,|��}t|�d�|�}|d||d�|��S)�ABased on mypy.plugins.dataclasses.DataclassAttribute.deserialize.r�)r�r�NrS)�copyr1�pop)r�r�r�r��typrSrSrT�deserializekszPydanticModelField.deserialize�sub_typerWcCsT|jdur(t�|jj��t|j||j�|_Wd�dS1s!wYdSdS)zxExpands type vars in the context of a subtype when an attribute is inherited
        from a generic super type.
        N)r�r4r�rVr�r5r�)r_r�r�rSrSrT�expand_typevar_from_subtypers

"��z.PydanticModelField.expand_typevar_from_subtypeN)r�rOr�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�r0r�r�r�r�rPr�F)r�r(r�r0r�r�rPr�)
r�r(r�r0r�r�r�r�rPr)�rPr)r�r(r�rr�r0rPr�)r�r(r�r0rPrW)r�r�r�r�r^r�rr�r��classmethodr�r�rSrSrSrTr��s

�#�
r�c@s0eZdZdZdd�Zeddd��Zd
d	d
�ZdS)�PydanticModelClassVarz�Based on mypy.plugins.dataclasses.DataclassAttribute.

    ClassVars are ignored by subclasses.

    Attributes:
        name: the ClassVar name
    cCs
||_dSrX�r�)r_r�rSrSrTr^�s
zPydanticModelClassVar.__init__r�rrPcCs|��}|di|��S)r�NrS)r�)r�r�rSrSrTr��sz!PydanticModelClassVar.deserializecCs
d|jiS)r�r�r�r�rSrSrTr��s�zPydanticModelClassVar.serializeN)r�rrPr�r�)r�r�r�r�r^r�r�r�rSrSrSrTr�{sr�c@seZdZUdZhd�Zded<d`dd�Zdadd�Zdbdd�Zdcdd�Z	dddd�Z
ded!d"�Zdfd%d&�Zdgd+d,�Z
dhd4d5�Zdid:d;�Zdid<d=�Zdjd?d@�ZdkdldFdG�ZedmdHdI��ZedndKdL��ZedodNdO��ZedmdPdQ��Z	AdkdpdXdY�ZdqdZd[�Zedrd]d^��Zd_S)srz�Transform 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�frozenr��alias_generatorr��populate_by_namezset[str]�tracked_config_fieldsr�rr��Expression | Statementr�r0rZrYrPrWcCs||_||_||_||_dSrX)�_cls�_reason�_apirZ)r_r�r�r�rZrSrSrTr^�s
z!PydanticModelTransformer.__init__r�cCs�|jj}tdd�|jdd�D��}|��}|�||�\}}|dus&|dur(dS|D]
}|jdur4dSq*tdd�|jdd�D��}|�||||�|�||||�|j	||j
|jdud�|��d	d
�|D�dd
�|D�|�
�d�|jt<dS)
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
        css�|]}t|jvVqdSrX)�ROOT_MODEL_FULLNAMErbrgrSrSrTrj�rkz5PydanticModelTransformer.transform.<locals>.<genexpr>N���FcsrdrX)rb�BASESETTINGS_FULLNAMErgrSrSrTrj�rkT)r�cS�i|]}|j|���qSrS�r�r��rh�fieldrSrSrTr��r�z6PydanticModelTransformer.transform.<locals>.<dictcomp>cSr�rSr�)rh�	class_varrSrSrTr��r�)�fields�
class_varsr�)r�r�rorp�collect_config�collect_fields_and_class_varsr��add_initializer�add_model_construct_method�
set_frozenr�r��adjust_decorator_signatures�get_values_dictr�r�)r_r��
is_root_modelr�r�rr��is_settingsrSrSrTr��s(

��z"PydanticModelTransformer.transformcs�|jjj��D]8}t|jt�r?|jjd�t�t�r?t�j	t
�r?�j	jtvr?�j	jt
kr:t�fdd�t�j�D��s?d|jj_qdS)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`.
        rc3s6�|]\}}�j|dkot|t�o|jdkVqdS)�mode�afterN)�	arg_namesrmr$�value)rh�ir���	first_decrSrTrj�s
� �
�zGPydanticModelTransformer.adjust_decorator_signatures.<locals>.<genexpr>TN)r�r��names�valuesrmrnr�original_decoratorsr�calleerrb�DECORATOR_FULLNAMES�MODEL_VALIDATOR_FULLNAMEro�	enumerater��func�is_class)r_rrrSrrTr�s �
���
��z4PydanticModelTransformer.adjust_decorator_signatures�ModelConfigDatac	Cs |j}t�}d}d}|j��D]\}}|�||�}|r"d}|�|�qd}|jjD]�}t|t	t
f�s3q)t|t	�r�|jd}	t|	t�rG|	j
dkrHq)t|jt�rmt|jj|jj�D]\}
}|
dur`qW|�|j|
|dd��qWnNt|jt�r�|jjD]\}}
t|t�s�qw|�|�|j|
��qwn.t|t
�r�|j
dkr�q)|jjD]}t|t	�s�q�|jd}	t|	t�s�q�|�|�|	j
|j��q�|r�|j�d|�nd}q)|s�|r�|r�|jr�|js�|jjr�t|j|�|jjd	d�D]&}t|j vr�q�|j�!t"|j#��|j td
��D]\}}|�$||��qq�|S)zhCollects the values of the config attributes that are used by the plugin, accounting for parent classes.FTNr�model_config)�	lax_extra�ConfigzYSpecifying config in two places is ambiguous, use either Config attribute or class kwargs�r�)%r�r�keywords�items�get_config_update�update�defs�bodyrmrr�lvaluesrr��rvaluer�ziprr�rr$r
r��fail�has_alias_generatorr�rZr��error_required_dynamic_aliasesr�rpr�r��add_plugin_dependencyr3rb�
setdefault)r_r�r��has_config_kwargs�has_config_from_namespacer��expr�config_data�stmt�lhs�arg_namer��key_expr�
value_expr�substmtr�r
rSrSrTr�s�
�

�
�




�����
�z'PydanticModelTransformer.collect_configrr�Jtuple[list[PydanticModelField] | None, list[PydanticModelClassVar] | None]cCs�|j}i}i}t|jjdd��D]b}t|jvrq|j�t|j	��|jtd�
�D]2\}}t�|||j�}	|	�
|j|j�|	||<|jj�|�}
|
r]|
jr]t|
jt�s]|j�d|
j�q+|jtd�
�D]\}}t�|�||<qgqt�}t�}|�|j�D]I}
|�|
||�}|dur�q�|
jd}t|t�s�J�t|t�r�|r�|jdkr�t|j|
�q�|�|j�|||j<q�t|t�r�|�|j�|||j<q�t|���t|���fS)	zACollects the fields for the model, accounting for parent classes.rr�r�z7BaseModel field may only be overridden by another fieldrNr�root) r��reversedr�rpr�r�r�r+r3rbr r�r�r�rr�rnrmr)r(r��set�%_get_assignment_statements_from_blockr#�$collect_field_or_class_var_from_stmtr%rr�� error_extra_fields_on_root_model�add�listr)r_rrr��found_fields�found_class_varsr�r�r�r��sym_node�current_field_names�current_class_vars_namesr1�maybe_fieldr2rSrSrTr<sN
���



�z6PydanticModelTransformer.collect_fields_and_class_varsr1r�Iterator[AssignmentStmt]ccsT�|jD]
}|js|�|�EdHq|jdur&|jjs(|�|j�EdHdSdSdSrX)r$�is_unreachabler;�	else_body)r_r1r$rSrSrT�,_get_assignment_statements_from_if_statement�s�
��zEPydanticModelTransformer._get_assignment_statements_from_if_statement�blockrccs>�|jD]}t|t�r|Vqt|t�r|�|�EdHqdSrX)r$rmrrrI)r_rJr1rSrSrTr;�s�


��z>PydanticModelTransformer._get_assignment_statements_from_blockrr� dict[str, PydanticModelClassVar]�1PydanticModelField | PydanticModelClassVar | NonecCs,|j}|jd}t|t�rt�|j�r|jdkrdS|jsKt|jt	�r<t|jj
t	�r<t|jj
j
t�r<|jj
j
jtvr<dS|j|vrCdSt
|j|�dS|jd}t|t�sWdSt�|j�rb|jdkrddS|jj�|j�}|durrdS|j}t|t�r|dSt|t�r�|j�d|�dSt|t�s�dS|jr�t|j�St|j�}t|t�r�|jjdkr�|j�d|�|�|�}	|�|�}
|jdur�|jr�|jr�|jj |jdd�}|r�||_n
|j�d	|�t!t"j#�|_|�$|�\}}
|
r�|j%s�|j&j'r�t(|j|�|�)|�}|�*||j|�}t+|j|
|	|
|||j,|j-||jd
�
S)a^Get pydantic model field from statement.

        Args:
            stmt: The statement.
            model_config: Configuration settings for the model.
            class_vars: ClassVars already known to be defined on the model.

        Returns:
            A pydantic model field if it could find the field in statement. Otherwise, `None`.
        rrNzFType aliases inside BaseModel definitions are not supported at runtimezdataclasses.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�r�).r�r%rmrrC�is_valid_field_namer��
new_syntaxr&rrrbr�error_untyped_fieldsr�r�rr�rnr!r'r(r)�is_classvarr�r?r�r8�get_has_default�
get_strictrM�is_inferred�analyze_simple_literal_typer6r;�
from_error�get_alias_infor�rZr�r*�is_field_frozen�_infer_dataclass_attr_init_typer�r�r�)r_r1rrr�r2rrrn�	node_typer�r�r�r�r�r��	init_typerSrSrTr<�s�
 
���




�


�

�
�z=PydanticModelTransformer.collect_field_or_class_var_from_stmtrrr%r�rOr�rr�c	Cs�|j}|jr|St|j�}t|t�s|S|j�d�}|rpt|jt�rc|j�d�}|s,J�|jr:tt	|j|j|��}nt
tj�St|t
�rT|jtttgkrTt|jd|�S|j�d|jj�d�|�|S|j�d|jj�d�|�|S)zvInfer __init__ argument type for an attribute.

        In particular, possibly use the signature of __set__.
        �__set__rMz(Unsupported signature for "__set__" in "�"zUnsupported "__set__" in ")r��implicitr?rmr8r�rnr�get_containing_type_infor5r6r;�unannotatedr7�	arg_kindsr
r	�	arg_typesr�r(r�)	r_rrr�r��default�t�setter�
super_info�setter_typerSrSrTrYs0


��z8PydanticModelTransformer._infer_dataclass_attr_init_typer��list[PydanticModelField]r�r	c
Cs�d|jjjvr|jjjdjsdS|jj}t|j�}|jdu}t|j	o&|j�}|j
|||||||dd�}	|r�|j�t
�j}
t|
t�sEJ�d|
jvr�|
jdj}t|t�sWJ�|dur�|jdur�|j}t|t�sjJ�t|j�D]+\}
}|dus�|�d�s�|�d�s�qo|j�|j|
�}t||�}|	�t||dt��qo|�||�s�td�}|	�t|ttj �dt!��t"|j|jd|	t#�d�dS)	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.
        r^NT)r�r��requires_dynamic_aliasesr�r	rr��__�_�kwargs)r��return_type)$r�r�r�plugin_generatedrZr�r�r�r�r)�get_field_argumentsr�rlr�rnrmr(rr�r7rr�
startswith�	anal_typerbr)�appendrr�should_init_forbid_extrar6r;r�r�
add_methodr9)r_r�r�r	rr�r�r�rir��base_settings_node�base_settings_init_node�	func_type�arg_idxr3�analyzed_variable_typer��varrSrSrTr5sF

�

z(PydanticModelTransformer.add_initializerc

Cs�|j�t�d�|j�t�d��g�}t|t�g�}ttd|�|dt�}t�	|jj
j��|j|dt
|j�dd||d�}Wd�n1sEwY|�||�satd�}	|�t|	ttj�dt��|rh||gn|g|}t|j|jd	|t|jj�dd
�dS)z�Adds 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_setNTF)r�r�rir�r	rrl�model_construct)r�rm�is_classmethod)r��
named_type�
BUILTINS_NAMEr>r9rr)rr4r�rVr�ror�r�rsrrr6r;r�rrtr�r@r�)
r_r�r�r	r�set_str�optional_set_str�fields_set_argumentr�rzrSrSrTrds4$��


�z3PydanticModelTransformer.add_model_construct_methodr�c
	Cs�|jj}|D]r}|j�|j�}|durX|j}t|t�r"|p|j|_	qt|t
�r1|jjs1|j�
�qzt|�}Wn
tyDt|�}Ynwd|�d|j�d�}	t|	|j|j�q|j||dd�}||_||_	|jd|j|_tt|�|j|j<qdS)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.
        Nzsym_node.node: r�r�F)r��.)r�r�rr�r�rnrmr)r��is_propertyr!r��final_iteration�deferrO�	TypeError�reprrar�r�rb�	_fullnamer%r)
r_r�r�r�r�r�rBrz�var_strr�rSrSrTr�s,
��z#PydanticModelTransformer.set_frozenFr�rr�ModelConfigData | NonecCs�||jvrdS|dkr1t|t�r|jdk}nt|t�r!|jdk}n|s*t||j|�dSt|d�S|dkrHd}t|t	�rC|j
dkrCd}t|d	�St|t	�r^|j
d
vr^tdi||j
dki��St||j|�dS)
z�Determines 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)r))�
builtins.True�builtins.Falser�rS)r�rmr$r
rr��error_invalid_config_valuer�rrrb)r_r�r�rr�r)rSrSrTr!�s(


	

z*PydanticModelTransformer.get_config_updatecCs�|j}t|t�r
dSt|t�rIt|jt�rI|jjtkrIt|j	|j
�D]$\}}|dus.|dkr5|jtuS|dkrFt|t
�oB|jdkSq"dSt|t�S)zUReturns a boolean indicating whether the field defined in `stmt` is a required field.FNrc�default_factoryr�)r&rmr&rrr"rb�FIELD_FULLNAMEr'r�rrarr�r1r/r�r�rSrSrTrR�s
"�z(PydanticModelTransformer.get_has_defaultr�cCs||j}t|t�r<t|jt�r<|jjtkr<t|j|j	�D] \}}|dkr$qt|t
�r9|jdkr1dS|jdkr9dSdSdS)zEReturns a the `strict` value of a field if defined, otherwise `None`.r�r�Tr�FN)r&rmrrr"rbr�r'r�rrr�rSrSrTrS�s"


z#PydanticModelTransformer.get_strict�tuple[str | None, bool]cCs�|j}t|t�r
dSt|t�rt|jt�r|jjtksdSt|j	�D]\}}|dkr+q"|j
|}t|t�r<|jdfSdSdS)aReturns 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&rmr&rrr"rbr�rrr�r$r
�r1r/rr3r�rSrSrTrW�s"
�
�

z'PydanticModelTransformer.get_alias_infocCs||j}t|t�r
dSt|t�rt|jt�r|jjtksdSt|j	�D]\}}|dkr;|j
|}t|t�o8|jdkSq"dS)alReturns whether the field is frozen, extracted from the declaration of the field defined in `stmt`.

        Note that this is only whether the field was declared to be frozen in a `<field_name> = Field(frozen=True)`
        sense; this does not determine whether the field is frozen because the entire model is frozen; that is
        handled separately.
        Fr�r�)r&rmr&rrr"rbr�rrr�rr�rSrSrTrXs
�
�
�z(PydanticModelTransformer.is_field_frozenr�r�r�rir��list[Argument]c	
	s.�jj����������f	dd�|D�}	|	S)z�Helper 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s@g|]}�r	|js|j����p���j��o|jdkd��qS)r8)r�r�r�r�r�r�r�)r�r�r�r�r��	r�r�rr	r�rir_r�r�rSrT�
<listcomp>9s"����z@PydanticModelTransformer.get_field_arguments.<locals>.<listcomp>)r�r�)
r_r�r�r�r�rir	rr��	argumentsrSr�rTro)s
�z,PydanticModelTransformer.get_field_argumentscCs.|js|�|t|j��rdS|jrdS|jjS)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�r)r�rZr�)r_r�r�rSrSrTrsIsz1PydanticModelTransformer.should_init_forbid_extrar)cCs8|D]}|jr
dSq|r|D]
}|jdurdSqdS)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�rSrSrTr�Vs�
�z1PydanticModelTransformer.is_dynamic_alias_presentN)
r�rr�r�r�r0rZrYrPrW)rPr�)rPrW)rPr)rrrr�rPr7)r1rrPrF)rJrrPrF)r1rrrrrKrPrL)rrr%r�rOr�rrPr�)
r�rhr�rr	r�rr�rPrW)r�rhr�r0r�r�rPrWr�)r�rOr�rrr�rPr�)r1rrPr�)r1rrPr�)r1rrPr�)r�rhr�r�r�r�r�r�rir�r	r�rr�r�r�rPr�)r�rhr�rrPr�)r�rhr)r�rPr�)r�r�r�r�r�r�r^r�rrrrIr;r<rYrrrr!�staticmethodrRrSrWrXrorsr�rSrSrSrTr�s<

	

$

L
D



&
/
(#!�
 
rc@sFeZdZdZ						ddd
d�Zddd�Zddd�Zddd�ZdS) rz(Pydantic mypy plugin model config class.Nr�r�r�r�r�r)r�cCs(||_||_||_||_||_||_dSrX)r�r�r�r�r)r�)r_r�r�r�r�r)r�rSrSrTr^hs	
zModelConfigData.__init__rPr}cCsdd�|j��D�S)z�Returns a dict of Pydantic model config names to their values.

        It includes the config if config value is not `None`.
        cSsi|]\}}|dur||�qSrXrS)rh�k�vrSrSrTr�}sz3ModelConfigData.get_values_dict.<locals>.<dictcomp>)�__dict__r r�rSrSrTrx�zModelConfigData.get_values_dictr�r�rWcCs2|durdS|����D]
\}}t|||�qdS)z$Update Pydantic model config values.N)rr r�)r_r�r�r�rSrSrTr"s
�zModelConfigData.updater�rOr
rcCs"t||�durt|||�dSdS)zFSet default value for Pydantic model config if config value is `None`.N)r�r�)r_r�r
rSrSrTr,�s�zModelConfigData.setdefault)NNNNNN)r�r�r�r�r�r�r�r�r)r�r�r�r�)r�r�rPrW)r�rOr
rrPrW)r�r�r�r�r^rr"r,rSrSrSrTres�

rzpydantic-ormzInvalid from_attributes call�Pydanticzpydantic-configzInvalid config valuezpydantic-aliaszDynamic alias disallowedzpydantic-unexpectedzUnexpected behaviorzpydantic-fieldzUntyped field disallowedzInvalid Field defaultsz!Extra field on RootModel subclass�
model_namer�r+r�rrWcC�|jd|�d�|td�dS)zCEmits an error when the model does not have `from_attributes=True`.r]z$" does not have from_attributes=True��codeN)r(�	ERROR_ORM)r�r�r�rSrSrTr���r�r�r0cCr�)z0Emits an error when the config value is invalid.zInvalid value for "Config.r]r�N)r(�ERROR_CONFIG)r�r�r�rSrSrTr��r�r�cC�|jd|td�dS)znEmits required dynamic aliases error.

    This will be called when `warn_required_dynamic_aliases=True`.
    z#Required dynamic aliases disallowedr�N)r(�ERROR_ALIAS�r�r�rSrSrTr*�r�r*r��8CheckerPluginInterface | SemanticAnalyzerPluginInterfacecCs4d}d|�d�}|d|�d�7}|j||td�dS)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)r(�ERROR_UNEXPECTED)r�r�r��link�full_messagerSrSrTr��sr�cCr�)z;Emits an error when there is an untyped field in the model.zUntyped fields disallowedr�N)r(�
ERROR_UNTYPEDr�rSrSrTrP�r�rPcCr�)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)r(�ERROR_EXTRA_FIELD_ROOT_MODELr�rSrSrTr=�r�r=F�8SemanticAnalyzerPluginInterface | CheckerPluginInterfacer�rr�r�rmr�r��tvar_def�TypeVarType | Noner}r�cCs|j}||jvr|j|}	|	jrt|	jt�r|jj�|	j�t|t	�r)|�
d�}
n|�dg�}
|rE|p8tt
|��}ttd�|dtd�g}n|pJt
|�}ttd�|dt�g}||}ggg}}
}|D]}|jslJd��|�|j�|
�|jj�|�|j�qct|||
||
�}|r�|g|_t||tt�g��}||_t||�|_||_|jd||_|j|_||jvr�t ||j�}|j||j|<|r�d|_!t||j�}||_|j|_d|_"t#|t$d�g|�}|j|_t%t&|�}	nt%t&|�}	d|	_|	|j|<|j'jj�|�dS)	zhVery closely related to `mypy.plugins.common.add_method_to_class`, with a few pydantic-specific changes.zbuiltins.functionr�NT�__pydantic_self__z"All arguments must be fully typed.r�r�)(r�rrnrmrnrr#r$�remover0r~�named_generic_typer<r@rr)r
r�rrr�r�r�r7�	variablesrr r2r�rrbr�r�rA�is_decoratedr}rrr%r�defn)r�r�r�r�rmr�r�r}r�rr�
function_type�firstrbrrar��	signaturer�r_namer��decrSrSrTrt�sZ





rtr��dict[str, Any] | NonecCs�|�d�sdStjdkrddl}nzddl}Wnty*ddl}|�d�YdSwt|d��
}|�	|�Wd�S1s@wYdS)z�Returns 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)��rzJNo TOML parser installed, cannot read configuration from `pyproject.toml`.�rb)
ry�sys�version_info�tomllib�tomli�ImportError�warnings�warn�open�load)r��toml_r��rfrSrSrTr�s



�$�r�)rNrOrPrQ)r|r-rPr:)r�rOr�r+r�rrPrW)r�rOr�r0r�rrPrW)r�r0r�rrPrW)r�rOr�r�r�rrPrW)r�r+r�rrPrW)NNF)r�r�r�rr�rOr�r�rmr:r�r�r�r�r}r�rPrW)r�rOrPr�)|r��
__future__rr��configparserr�typingrrr�mypy.errorcodesr�mypy.expandtyperr	�
mypy.nodesr
rrr
rrrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)�mypy.optionsr*�mypy.pluginr+r,r-r.r/r0�mypy.plugins.commonr1�mypy.semanalr2�mypy.server.triggerr3�
mypy.stater4�mypy.typeopsr5�
mypy.typesr6r7r8r9r:r;r<r=r>r?�
mypy.typevarsr@�	mypy.utilrA�mypy.versionrB�mypy_version�pydantic._internalrC�pydantic.versionrDr�r�rfr�r�rtr��DATACLASS_FULLNAMErr�MYPY_VERSION_TUPLErrUrRrYrzr�r�rrr�r�r�r�r��ERROR_FIELD_DEFAULTSr�r�r�r*r�rPr=rtr�rSrSrSrT�<module>s��" 0

6
.V'





�X