o
    h%                     @   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-metadataz.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   d/var/www/html/construction_image-detection-poc/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 )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_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   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 )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)r]   debug_dataclass_transformclsinfodeclared_metaclassgetattrtyper   )rb   r   info_metaclassrR   rR   rS   rx      s   
z8PydanticPlugin._pydantic_model_metaclass_marker_callbackr
   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|j}t|dd	}|rtd
d |D rt fdd|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  argsNc                 s   s    | ]}t |tV  qd S r[   )ro   r>   )rj   argrR   rR   rS   rl      s    z:PydanticPlugin._pydantic_field_callback.<locals>.<genexpr>c                 3   s    | ]} V  qd S r[   rR   )rj   _default_any_typerR   rS   rl      s    )default_return_typecallee_arg_namesr   +error_default_and_default_factory_specifiedapicontext	arg_typesro   r   r9   r   itemsr6   ret_typer   allrL   )	rb   r   default_argsdefault_factory_argsdefault_typedefault_argdefault_factory_typer   r   rR   r   rS   r|      s8   	




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   toml_configconfigkey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   ctx_type
model_typedetail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   >   extrafrozenr   allow_mutationalias_generatorallow_population_by_field_name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>NFT)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   original_decoratorsr   calleer   re   
_NAMESPACEfuncis_class)rb   r   ru   	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.
        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rqg }|j%t&t'| |j$t# d ( D ]-\ } |vrt)||}|   || 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   
new_syntaxr]   r   error_untyped_fieldsr   r   r   r   rp   r!   r)   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   known_fieldsr   lhsru   rp   r  r  r  
all_fieldsr   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  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.str_fields_setNTFr  z.object_PydanticBaseModelrK   )r      )r      r   z
.construct)	namespace	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;   from_omitted_genericsr(   rE   r%   r   r   r   ro   r!  )rb   r   r   set_stroptional_set_strfields_set_argumentconstruct_argumentsobj_typeself_tvar_nametvar_fullnametvd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)   is_propertyr!   r   final_iterationdeferr   	TypeErrorreprrd   r   to_varrg   r   	_fullnamer%   r   )
rb   r   r   r   r   r   sym_noder#  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   forbid)forbid_extrar   Tzbuiltins.NoneF)r   )builtins.Truezbuiltins.FalserE  rR   )r	  ro   r   r   r   rvaluer#   r   r   error_invalid_config_valuer   r   r   re   )rb   r   r  rD  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)rF  ro   r&   r@   r   r   r   r   type_has_implicit_defaultr   r   r"   re   r{   zipr   	arg_namesrd   r   )r   r   r  expr
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   )rM  rR   rR   rS   rH  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)rF  ro   r&   r   r   r"   re   r{   	enumeraterJ  r   r#   r   )r   rK  i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   rS  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   rD  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   rV    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:   rH  r	   r  r   r  r  rV  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  rQ  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_annotationinitializerkind)
r   r   r5   r;   r   r   r?  r  r   r   )rb   r   r  rQ  r  rZ  rR   rR   rS   rR    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   rR  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   NrD  r   r   r   r   r   c                 C   rX  r[   )rD  r   r   r   r   r   )rb   rD  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   r_  r`  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 call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)rb  r   r   rR   rR   rS   r        r   r   c                 C   rc  )NzInvalid value for "Config.rd  re  )rg  ERROR_CONFIG)r   r   r   rR   rR   rS   rG    ri  rG  c                 C      | j d|td d S )Nz#Required dynamic aliases disallowedre  )rg  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!re  )rg  ERROR_UNEXPECTED)r   r   r   linkfull_messagerR   rR   rS   r   &  s   r   c                 C   rk  )NzUntyped fields disallowedre  )rg  ERROR_UNTYPEDrm  rR   rR   rS   r  0  r   r  c                 C   rk  )Nz>Field default and default_factory cannot be specified togetherre  )rg  ERROR_FIELD_DEFAULTSrm  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|_t||tt g}||_t|||_||_t|d | |_ |j!|_!||jv rt"||j}|j| |j|< |rd|_#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
    _clsN__pydantic_self__z"All arguments must be fully typed.z	.functionrK   Tr^  )*r   r   r   plugin_generatedro   rp   r   r   r   r  rA   r   r)   r<   make_normalizedr   rZ  r  r   rY  r\  r   r.  r/  r6   	variablesr   r    r3   r   r   rg   r@  r  rB   is_decoratedr-  r   r   r%   r   defn)r   r   r   r*  r+  r,  r-  rt  r   ru   firstr   rJ  	arg_kindsr   function_type	signaturer   r_namer`  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r  fnrR   rR   rS   rg        rg   c                 C   r  r  )r   r  r  rR   rR   rS   r     r  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   	read_modetoml_r  rfrR   rR   rS   r     s*   



$r   )NNFF)|r  configparserr   typingr   r   r   r   r   r   r	   r
   
TypingTyper   mypy.errorcodesr   
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)   mypy.optionsr*   mypy.pluginr+   r,   r-   r.   r/   r0   r1   mypy.pluginsr2   mypy.semanalr3   mypy.server.triggerr4   
mypy.typesr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   mypy.typevarsrA   	mypy.utilrB   mypy.versionrC   mypy_versionpydantic.v1.utilsrD   rE   r  r   r   r   r   rh   r   rw   r{   r   r   rN   rT   r   r/  rY   rX   r\   r   r   r   r   rh  rj  rl  ro  rr  rs  r   rG  r   r   r  r   r   r!  rg   r   r   rR   rR   rR   rS   <module>   s    ,|$	<





u%   2%


	

S
"
