U
    ={fv                     @   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" eUk
r   d dl>mHZT Y nX dZVdZWeXdd ZYeY dZZeY dZ[eY dZ\eY dZ]eY dZ^e_e
e`df dddZaeaeQZbebdkr0dnd Zcd!ZPe_d"dd#d$ZdG d%d& d&e5ZeG d'd( d(Zfe4ed)d*d+ZgG d,d- d-ZhG d.d/ d/ZiG d0d1 d1Zjed2d3d4Zked5d6d4Zled7d8d4Zmed9d:d4Zned;d<d4Zoed;d=d4Zpe_e1edd>d?d@Zqe_e7eddAdBdCZre7eddDdEdFZse_ee1e7f eddGdHdIZte7eddDdJdKZue1eddDdLdMZvdZe2e_ee eee eeT ewewddO	dPdQZxeee(f e_dRdSdTZyeee(f e_dRdUdVZze_eee_ef  dWdXdYZ{dS )[    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returnc                 C   s   t tt| dd dS )N+r   .)tuplemapint	partitionsplitrH    rR   O/var/www/html/Darija-Ai-API/env/lib/python3.8/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edd fddZeddddZeeee	gdf  dd	d
Z
eddddZeeeegef  dddZeeee	gdf  dddZeeeef dddZe	ddddZe	ddddZeddddZ  ZS )rX   NoptionsrI   c                    s&   t || _| j | _t | d S N)PydanticPluginConfigplugin_configto_data_plugin_datasuper__init__)selfr[   	__class__rR   rS   rb   m   s    
zPydanticPlugin.__init__z+Optional[Callable[[ClassDefContext], None]])fullnamerI   c                 C   s:   |  |}|r6t|jtr6tdd |jjD r6| jS d S )Nc                 s   s   | ]}t |tkV  qd S r\   )get_fullnameBASEMODEL_FULLNAME.0baserR   rR   rS   	<genexpr>v   s     z5PydanticPlugin.get_base_class_hook.<locals>.<genexpr>)lookup_fully_qualified
isinstancenoder'   anymro$_pydantic_model_class_maker_callbackrc   rf   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rc   rf   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\   )rm   rf   FIELD_FULLNAME_pydantic_field_callbackrs   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_callbackrx   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   Zdataclass_class_maker_callbackrx   rR   rR   rS   get_class_decorator_hook   s    z'PydanticPlugin.get_class_decorator_hookctxrI   c                 C   s   | j S )zjReturn all plugin config data.

        Used by mypy to determine if cache needs to be discarded.
        )r`   )rc   r   rR   rR   rS   report_config_data   s    z!PydanticPlugin.report_config_datac                 C   s   t || j}|  d S r\   )PydanticModelTransformerr^   	transform)rc   r   ZtransformerrR   rR   rS   rr      s    z3PydanticPlugin._pydantic_model_class_maker_callbackc                 C   s<   | j jrdS |jjj}|s"tdt|jddr8d|j_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infoZdeclared_metaclassAssertionErrorgetattrtyper   )rc   r   Zinfo_metaclassrR   rR   rS   rw      s    
z8PydanticPlugin._pydantic_model_metaclass_marker_callbackr
   c           	         s   |j  |jd dkstd|jd dks2td|jd }|jd }|r`|r`t|j|j  S |r|jd d }|d }t|t	s|S n|r|jd d }t|t
rtdkr|jd }n| d }t|tr|j}t|dd	}|rtd
d |D rt 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\   )rn   r>   )rj   argrR   rR   rS   rl      s     z:PydanticPlugin._pydantic_field_callback.<locals>.<genexpr>c                 3   s   | ]
} V  qd S r\   rR   )rj   _Zdefault_any_typerR   rS   rl      s     )default_return_typeZcallee_arg_namesr   r   +error_default_and_default_factory_specifiedapicontext	arg_typesrn   r   r9   r   itemsr6   ret_typer   allrL   )	rc   r   Zdefault_argsZdefault_factory_argsZdefault_typeZdefault_argZdefault_factory_typer   r   rR   r   rS   r{      s6    	



z'PydanticPlugin._pydantic_field_callback)__name__
__module____qualname__r*   rb   strru   r   r   r,   ry   r|   r.   r
   r   r   r0   r   r   r   rr   rw   r-   r{   __classcell__rR   rR   rd   rS   rX   l   s   	rX   c                   @   s`   e Zd ZU dZeed< eed< eed< eed< eed< eddd	d
Zee	e
f dddZdS )r]   )init_forbid_extra
init_typedwarn_required_dynamic_aliaseswarn_untyped_fieldsr   r   r   r   r   r   NrZ   c                 C   s   |j d krd S t|j }|d k	rr|di di }| jD ]4}||d}t|tsbtd| t| || q:n:t }|	|j  | jD ] }|j
t|dd}t| || qd S )NZtoolrF   Fz/Configuration value must be a boolean for key: )fallback)config_file
parse_tomlget	__slots__rn   bool
ValueErrorsetattrr   read
getbooleanCONFIGFILE_KEY)rc   r[   Ztoml_configconfigkeyZsettingr^   rR   rR   rS   rb      s    




zPydanticPluginConfig.__init__rI   c                    s    fdd j D S )Nc                    s   i | ]}|t  |qS rR   )r   )rj   r   rc   rR   rS   
<dictcomp>  s      z0PydanticPluginConfig.to_data.<locals>.<dictcomp>)r   r   rR   r   rS   r_     s    zPydanticPluginConfig.to_data)r   r   r   r   r   __annotations__r*   rb   r   r   r   r_   rR   rR   rR   rS   r]      s   
r]   r   c                 C   s   | j }t|tr|j}t|tr4t|jtr4|j}n<t|trD|}n,d| d|jj d}t	|| j
| j | jS |j jt}|dkr| jS |di d}|dk	rt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   rn   r<   itemr6   r   r7   re   r   error_unexpected_behaviorr   r   r   metadatar   METADATA_KEYerror_from_ormget_name)r   Zctx_typeZ
model_typedetailZpydantic_metadatar   rR   rR   rS   r~     s"    

r~   c                   @   sn  e Zd ZU ddddddhZee ed< eedd	d
dZ	ddddZ
ddddZddddZded dddZed deddddZed ddddZed edddd Zeed d!d"d#Zeeeeed$d%d&Zeee ed'd(d)Zeeeee ef d*d+d,Zed eeeee d-d.d/Zed ded0d1d2Z eed eed3d4d5Z!dS )6r   extraallow_mutationfrozenr   allow_population_by_field_namealias_generatortracked_config_fieldsN)r   r^   rI   c                 C   s   || _ || _d S r\   )_ctxr^   )rc   r   r^   rR   rR   rS   rb   )  s    z!PydanticModelTransformer.__init__r   c                 C   s   | j }|jj}|   |  }| |}tdd |jdd D }| ||| | 	| | j
||jdkpt|jdk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   s   | ]}t |tkV  qd S r\   )rg   BASESETTINGS_FULLNAMEri   rR   rR   rS   rl   =  s     z5PydanticModelTransformer.transform.<locals>.<genexpr>NFT)r   c                 S   s   i | ]}|j | qS rR   )name	serializerj   fieldrR   rR   rS   r   B  s      z6PydanticModelTransformer.transform.<locals>.<dictcomp>)fieldsr   )r   r   r   adjust_validator_signaturescollect_configcollect_fieldsrp   rq   add_initializeradd_construct_method
set_frozenr   r   set_values_dictr   r   )rc   r   r   r   r   is_settingsrR   rR   rS   r   -  s    


z"PydanticModelTransformer.transformc                 C   sh   | j jjj D ]R\}}t|jtr|jjd }t|t	rt|j
tr|j
jt dkrd|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   rn   ro   r   Zoriginal_decoratorsr   calleer   rf   
_NAMESPACEfuncis_class)rc   r   rt   Z	first_decrR   rR   rS   r   F  s    
z4PydanticModelTransformer.adjust_validator_signaturesModelConfigDatac           	      C   s   | j }|j}t }|jjD ]d}t|ts*q|jdkr|jjD ] }t|tsLq<|	| 
| q<|jr|js| jjrt|j| q|jjdd D ]L}t|jkrq|jtt| |jt d  D ]\}}||| qq|S )zz
        Collects the values of the config attributes that are used by the plugin, accounting for parent classes.
        ZConfigr   Nr   )r   r   r   defsbodyrn   r   r   r   updateget_config_updatehas_alias_generatorr   r^   r   error_required_dynamic_aliasesr   r   rq   r   r   add_plugin_dependencyr4   rg   r   
setdefault)	rc   r   r   r   stmtsubstmtr   r   valuerR   rR   rS   r   X  s2    



z'PydanticModelTransformer.collect_configPydanticModelField)model_configrI   c                    s  | j }| j j}g }t }|jjD ]}t|ts0q |jd }t|tr t	|j
sPq |jsj| jjrjt|j| |jj|j
}|dkrq |j}	t|	trq t|	tsq |	jrq | |||}
| |\}}|r|js| jjrt|j| |t|j
|
|||j|jd | |j
 q |! }|jj"dd D ]}t#|j$kr>q*g }|j%t&t'| |j$t# d ( D ]^\ } |krt)||}|   || n( fdd|D \}|*| || qh|| }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   rn   r   lvaluesr   rD   r   Z
new_syntaxr^   r   error_untyped_fieldsr   r   r   r   ro   r!   r)   Zis_classvarget_is_requiredget_alias_infor   r   r   appendr   r   r   addcopyrq   r   r   r   r4   rg   r   deserializeremove)rc   r   r   r   r   Zknown_fieldsr   lhsrt   ro   r   r   r   Z
all_fieldsr   Zsuperclass_fieldsdatar   rR   r   rS   r   w  st    







z'PydanticModelTransformer.collect_fields)r   r   r   rI   c           
      C   s   | j }| jj}|jdk	}|p,t|jo*|j }| j||||d}| ||sntd}	|	t
|	ttjdt d|jjjkrt|d|t  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kwargsNrb   )r   r^   r   r   r   r   get_field_argumentsshould_init_forbid_extrar)   r   r   r5   r;   explicitr   r   r   r   
add_methodr8   )
rc   r   r   r   r   r   r  r  Zinit_argumentsvarrR   rR   rS   r     s"    
   z(PydanticModelTransformer.add_initializer)r   rI   c              	   C   s0  | 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rt||	tdg |ttj}
t||	g |ttj}nt||	dg |}
t||	g |}tt||j
jj|< t|
tr|
}nt|
}t|d||||
dd dS )z
        Adds a fully typed `construct` classmethod to the class.

        Similar to the fields-aware __init__ method, but always uses the field names (not aliases),
        and does not treat settings fields as optional.
        z.setz.strZ_fields_setNTFr   z.objectZ_PydanticBaseModelrK   )r      r   	construct)return_type	self_typetvar_defis_classmethod)r   r   
named_typeBUILTINS_NAMEr?   r8   r   r)   r   r  r   rf   r   r>   r=   r5   r;   Zfrom_omitted_genericsr(   rE   r%   r   r   r   rn   r  )rc   r   r   Zset_strZoptional_set_strZfields_set_argumentZconstruct_argumentsobj_typeZself_tvar_nameZtvar_fullnameZtvdZself_tvar_exprr  rR   rR   rS   r     sP    $
z-PydanticModelTransformer.add_construct_method)r   r   rI   c           
   	   C   s   | j }|jj}|D ]}|j|j}|dk	r|j}t|trD||_	qt|t
rb|jjsb|j  qzt|}W n tk
r   t|}Y nX 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   ro   rn   r)   Zis_propertyr!   r   Zfinal_iterationZdeferr   	TypeErrorreprre   r   to_varrg   r   	_fullnamer%   r   )
rc   r   r   r   r   r   Zsym_noder  Zvar_strr   rR   rR   rS   r     s*    
z#PydanticModelTransformer.set_frozen)r   rI   c                 C   s   |j d }t|tr |j| jks$dS |jdkrt|jtrH|jjdk}n0t|jtrb|jjdk}nt	|j| j
j| dS t|dS |jdkrd}t|jtr|jjdkrd	}t|d
S t|jtr|jjdkrtf |j|jjdkiS t	|j| j
j| dS )z
        Determines the config update due to a single statement in the Config class definition.

        Warns if a tracked config attribute is set to a value the plugin doesn't know how to interpret (e.g., an int)
        r   Nr   Zforbid)forbid_extrar   Tzbuiltins.NoneF)r   )builtins.Truezbuiltins.Falser  )r   rn   r   r   r   rvaluer#   r   r   error_invalid_config_valuer   r   r   rf   )rc   r   r   r  r   rR   rR   rS   r   8  s(    




z*PydanticModelTransformer.get_config_update)r   r   r   rI   c                 C   s   |j }t|tr.t| j|j j}t| S t|t	rt|j
tr|j
jtkrt|j|jD ]4\}}|dksv|dkr|jtk  S |dkr^ dS q^t| j|j j}t| S t|tS )zg
        Returns a boolean indicating whether the field defined in `stmt` is a required field.
        Nr   r   F)r  rn   r&   r@   r   r   r   r   type_has_implicit_defaultr   r   r"   rf   rz   zipr   	arg_namesre   r   )r   r   r   exprZ
value_typer   r   rR   rR   rS   r   T  s    
"z(PydanticModelTransformer.get_is_required)type_rI   c                 C   s4   t | trdS t | tr0tdd | jD r0d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\   )rn   r8   r5   )rj   r   rR   rR   rS   rl   x  s    zEPydanticModelTransformer.type_has_implicit_default.<locals>.<genexpr>F)rn   r5   r?   rp   r   )r  rR   rR   rS   r  n  s    
z2PydanticModelTransformer.type_has_implicit_default)r   rI   c                 C   s   | j }t|trdS t|tr6t|jtr6|jjtks:dS t|j	D ]:\}}|dkrVqD|j
| }t|trx|jdf  S  dS qDdS )a   
        Returns a pair (alias, has_dynamic_alias), extracted from the declaration of the field defined in `stmt`.

        `has_dynamic_alias` is True if and only if an alias is provided, but not as a string literal.
        If `has_dynamic_alias` is True, `alias` will be None.
        )NFr   F)NT)r  rn   r&   r   r   r"   rf   rz   	enumerater  r   r#   r   )r   r  iZarg_namer   rR   rR   rS   r     s$    




z'PydanticModelTransformer.get_alias_info)r   r   r  r  rI   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   )rc   r   r   r  r  	argumentsrR   r#  rS   r    s
    
z,PydanticModelTransformer.get_field_arguments)r   r   rI   c                 C   s.   |j s| |t|jrdS |jr&dS | jjS )aH  
        Indicates whether the generated `__init__` should get a `**kwargs` at the end of its signature

        We disallow arbitrary kwargs if the extra config setting is "forbid", or if the plugin config says to,
        *unless* a required dynamic alias is present (since then we can't determine a valid signature).
        FT)r   is_dynamic_alias_presentr   r   r  r^   r   )rc   r   r   rR   rR   rS   r    s    z1PydanticModelTransformer.should_init_forbid_extra)r   r   rI   c                 C   s8   | D ]}|j r dS q|r4| D ]}|jdkr dS qdS )z
        Returns whether any fields on the model have a "dynamic alias", i.e., an alias that cannot be
        determined during static analysis.
        TNF)r   r   )r   r   r   rR   rR   rS   r&    s    
z1PydanticModelTransformer.is_dynamic_alias_present)"r   r   r   r   r   r   r   r,   r]   rb   r   r   r   r   r   r   r   r   r   r   r   r   staticmethodr   r   r   r:   r  r	   r   r   r  r  r&  rR   rR   rR   rS   r     s>   
	T6!   r   c                   @   st   e Zd Zeeee eeedddZeee	dddZ
eeeeeddd	Zed
ddZeeed dddZdS )r   r   c                 C   s(   || _ || _|| _|| _|| _|| _d S r\   r   )rc   r   r   r   r   r   r   rR   rR   rS   rb     s    zPydanticModelField.__init__)r   r  rI   c                 C   s,   | j }|r| jd k	r| j}t||| j  jS r\   )r   r   r)   r   )rc   r   r  r   rR   rR   rS   r    s    zPydanticModelField.to_var)r   r   r!  r  rI   c                 C   sR   |r"|| j  jd k	r"|| j  j}n
ttj}t| |||d |sF| jsJtnt	dS )N)variabletype_annotationZinitializerkind)
r   r   r5   r;   r  r   r  r   r   r   )rc   r   r   r!  r  r)  rR   rR   rS   r"    s    

zPydanticModelField.to_argumentr   c                 C   s   | j S r\   )__dict__r   rR   rR   rS   r     s    zPydanticModelField.serialize)r   r   rI   c                 C   s
   | f |S r\   rR   )r   r   r   rR   rR   rS   r     s    zPydanticModelField.deserializeN)r   r   r   r   r   r   rN   rb   r'   r)   r  r   r"  r   r   classmethodr   rR   rR   rR   rS   r     s        
r   c                   @   sz   e Zd Zdee ee ee ee ee ee dddZeeef dddZ	ed  ddd	d
Z
eeddddZdS )r   Nr  r   r   r   r   r   c                 C   s(   || _ || _|| _|| _|| _|| _d S r\   r-  )rc   r  r   r   r   r   r   rR   rR   rS   rb     s    	zModelConfigData.__init__r   c                 C   s   dd | j  D S )Nc                 S   s   i | ]\}}|d k	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      s    zModelConfigData.set_values_dict)r   rI   c                 C   s2   |d krd S |   D ]\}}t| || qd S r\   )r   r   r   )rc   r   r.  r/  rR   rR   rS   r     s    zModelConfigData.update)r   r   rI   c                 C   s   t | |d krt| || d S r\   )r   r   )rc   r   r   rR   rR   rS   r   	  s    zModelConfigData.setdefault)NNNNNN)r   r   r   r   r   rb   r   r   r   r   r   r   rR   rR   rR   rS   r     s"         r   zpydantic-ormzInvalid from_orm callZPydanticzpydantic-configzInvalid config valuezpydantic-aliaszDynamic alias disallowedzpydantic-unexpectedzUnexpected behaviorzpydantic-fieldzUntyped field disallowedzInvalid Field defaults)
model_namer   r   rI   c                 C   s   |j d|  d|td d S )N"z" does not have orm_mode=Truecode)fail	ERROR_ORM)r0  r   r   rR   rR   rS   r     s    r   )r   r   r   rI   c                 C   s   |j d|  d|td d S )NzInvalid value for "Config.r1  r2  )r4  ERROR_CONFIG)r   r   r   rR   rR   rS   r    s    r  )r   r   rI   c                 C   s   | j d|td d S )Nz#Required dynamic aliases disallowedr2  )r4  ERROR_ALIASr   r   rR   rR   rS   r     s    r   )r   r   r   rI   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!r2  )r4  ERROR_UNEXPECTED)r   r   r   linkZfull_messagerR   rR   rS   r   "  s    r   c                 C   s   | j d|td d S )NzUntyped fields disallowedr2  )r4  ERROR_UNTYPEDr8  rR   rR   rS   r   ,  s    r   c                 C   s   | j d|td d S )Nz>Field default and default_factory cannot be specified togetherr2  )r4  ERROR_FIELD_DEFAULTSr8  rR   rR   rS   r   0  s    r   F)	r   r   r   r  r  r  r  is_newrI   c                 C   s  | j j}||jkr@|j| }	|	jr@t|	jtr@| j jj	|	j |pJt
|}|sT|rpttdt|dtg}
n |pzt
|}ttd|dtg}
|
| }g g g   }}}|D ]:}|jstd||j |t|j ||j q| jt d}t|||||}|r|g|_t||tt g}||_t|||_||_t |d | |_!|j"|_"||jk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
    _clsNZ__pydantic_self__z"All arguments must be fully typed.z	.functionrK   Tr,  )+r   r   r   Zplugin_generatedrn   ro   r   r   r   r   rA   r   r)   r<   Zmake_normalizedr   r)  r   r   r   r(  r*  r   r  r  r6   	variablesr   r    r3   r   r   rg   r  r   rB   Zis_decoratedr  r   r   r%   r   Zdefn)r   r   r   r  r  r  r  r>  r   rt   firstr   r  Z	arg_kindsr   Zfunction_type	signaturer   Zr_namer/  decrR   rR   rS   r  4  sV    



r  )xrI   c                 C   s   | j }t|r| S |S zc
    Used for compatibility with mypy 0.740; can be dropped once support for 0.740 is dropped.
    )rf   callablerD  fnrR   rR   rS   rg     s    rg   c                 C   s   | j }t|r| S |S rE  )r   rF  rG  rR   rR   rS   r     s    r   )r   rI   c                 C   s   |  dsd S d}tjdkr&dd l}n^zdd l}W nP tk
r   d}zdd l}W n* tk
r|   dd l}|d Y Y d S X Y nX t	| |}|
|W  5 Q R  S Q R X d S )Nz.tomlrb)      r   rzJNo TOML parser installed, cannot read configuration from `pyproject.toml`.)r}   sysversion_infoZtomllibtomliImportErrortomlwarningswarnopenload)r   Z	read_modeZtoml_rR  rfrR   rR   rS   r     s"    



r   )NNFF)|rM  configparserr   typingr   r   r   r   r   r   r	   r
   Z
TypingTyper   Zmypy.errorcodesr   Z
mypy.nodesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   Zmypy.optionsr*   Zmypy.pluginr+   r,   r-   r.   r/   r0   r1   Zmypy.pluginsr2   Zmypy.semanalr3   Zmypy.server.triggerr4   Z
mypy.typesr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   Zmypy.typevarsrA   Z	mypy.utilrB   Zmypy.versionrC   Zmypy_versionZpydantic.v1.utilsrD   rE   rP  r   r   r   r   rh   r   rv   rz   r   r   rN   rT   r   r  rY   rX   r]   r~   r   r   r   r5  r6  r7  r:  r<  r=  r   r  r   r   r   r   r   r  rg   r   r   rR   rR   rR   rS   <module>   s   ,|$	<





u%   .% 
 
	    S

