
    4g%                     j   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 	 d dl>mTZT 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Za eaeQ      Zbebdk\  rdnd Zcd!ZPde_dd"fd#Zd G d$ d%e5      Ze G d& d'      Zfd(e4defd)Zg G d* d+      Zh G d, d-      Zi G d. d/      Zj ed0d1d2      Zk ed3d4d2      Zl ed5d6d2      Zm ed7d8d2      Zn ed9d:d2      Zo ed9d;d2      Zpd<e_d=e1d>eddfd?Zqd@e_d=e7d>eddfdAZrd=e7d>eddfdBZsdCe_d=ee1e7f   d>eddfdDZtd=e7d>eddfdEZud=e1d>eddfdFZv	 	 	 	 dSd(e2d@e_dGee   dHedIee   dJeeT   dKewdLewddfdMZxdNeee(f   de_fdOZydNeee(f   de_fdPZzdQe_deee_ef      fdRZ{y# eU$ r
 d dl>mHZT Y ew xY w)T    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                 v    t        t        t        | j                  d      d   j	                  d                  S )N+r   .)tuplemapint	partitionsplitrI   s    f/var/www/python.lazyprojects.co.uk/rdoDiscordBot/venv/lib/python3.12/site-packages/pydantic/v1/mypy.pyparse_mypy_versionrU   W   s/    S'++C0399#>?@@    )r   i  builtins__builtins__   zTypingType[Plugin]c                     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).
    )PydanticPluginrS   s    rT   pluginr\   b   s
     rV   c                        e Zd Zdeddf fdZdeddfdZdedeee	gdf      fdZ
dedd	fd
Zdedeeegef      fdZdedeee	gdf      fdZdedeeef   fdZde	ddfdZde	ddfdZdeddfdZ xZS )r[   optionsrJ   Nc                     t        |      | _        | j                  j                         | _        t        |   |       y N)PydanticPluginConfigplugin_configto_data_plugin_datasuper__init__)selfr^   	__class__s     rT   rf   zPydanticPlugin.__init__m   s4    1': ..668!rV   fullnamez+Optional[Callable[[ClassDefContext], None]]c                     | j                  |      }|rLt        |j                  t              r2t	        d |j                  j
                  D              r| j                  S y )Nc              3   @   K   | ]  }t        |      t        k(    y wr`   )get_fullnameBASEMODEL_FULLNAME.0bases     rT   	<genexpr>z5PydanticPlugin.get_base_class_hook.<locals>.<genexpr>v   s     U<%);;   )lookup_fully_qualified
isinstancenoder(   anymro$_pydantic_model_class_maker_callbackrg   ri   syms      rT   get_base_class_hookz"PydanticPlugin.get_base_class_hookr   sG    ))(3:chh1UUU@@@rV   c                 .    |t         k(  r| j                  S y r`   )MODEL_METACLASS_FULLNAME)_pydantic_model_metaclass_marker_callbackrg   ri   s     rT   get_metaclass_hookz!PydanticPlugin.get_metaclass_hookz   s    //AAArV   z+Optional[Callable[[FunctionContext], Type]]c                 h    | j                  |      }|r|j                  t        k(  r| j                  S y r`   )rs   ri   FIELD_FULLNAME_pydantic_field_callbackry   s      rT   get_function_hookz PydanticPlugin.get_function_hook   s/    ))(33<<>1000rV   c                 2    |j                  d      rt        S y )Nz	.from_orm)endswithfrom_orm_callbackr   s     rT   get_method_hookzPydanticPlugin.get_method_hook   s    [)$$rV   c                 H    |t         k(  rt        dk  rt        j                  S y)zMark pydantic.dataclasses as dataclass.

        Mypy version 1.1.1 added support for `@dataclass_transform` decorator.
        )   r   N)DATACLASS_FULLNAMEMYPY_VERSION_TUPLEr3   dataclass_class_maker_callbackr   s     rT   get_class_decorator_hookz'PydanticPlugin.get_class_decorator_hook   s$    
 )).@6.I===rV   ctxc                     | j                   S )zjReturn all plugin config data.

        Used by mypy to determine if cache needs to be discarded.
        )rd   )rg   r   s     rT   report_config_dataz!PydanticPlugin.report_config_data   s    
    rV   c                 P    t        || j                        }|j                          y r`   )PydanticModelTransformerrb   	transform)rg   r   transformers      rT   rx   z3PydanticPlugin._pydantic_model_class_maker_callback   s     .sD4F4FGrV   c                     | j                   j                  ry|j                  j                  j                  }|sJ d       t        |j                  dd      rd|j                  _        yy)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_transformclsinfodeclared_metaclassgetattrtyper   )rg   r   info_metaclasss      rT   r~   z8PydanticPlugin._pydantic_model_metaclass_marker_callback   s^     7788NNN~>&&(BDI;?N8 JrV   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 |r+|j                  d   d   }|d   }t        |t              s|S 	S |r|j                  d   d   }t        |t              r,t        dkD  r|j                  d   }n|j                         d   }t        |t              rH|j                  }t        |dd	      }|r+t        d
 |D              rt!        	f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              3   <   K   | ]  }t        |t                y wr`   )rt   r?   )ro   args     rT   rq   z:PydanticPlugin._pydantic_field_callback.<locals>.<genexpr>   s     H4C:c;74s   c              3   "   K   | ]  }  y wr`    )ro   _default_any_types     rT   rq   z:PydanticPlugin._pydantic_field_callback.<locals>.<genexpr>   s     -M1.>s   )default_return_typecallee_arg_namesr   +error_default_and_default_factory_specifiedapicontext	arg_typesrt   r   r:   r   itemsr7   ret_typer   allrN   )
rg   r   default_argsdefault_factory_argsdefault_typedefault_argdefault_factory_typer   r   r   s
            @rT   r   z'PydanticPlugin._pydantic_field_callback   sl    22##A&)3g5gg3##A&*;;x=xx;xx{"xx{07M##==+A.L&q/K k<8##2  / "#&==#3A#6  .
;%0+?+E+Ea+H( ,@+E+E+G+J(.=/88 x6H4HH(--M-M(MrV   )__name__
__module____qualname__r+   rf   strr{   r   r   r-   r   r   r/   r   r   r   r1   r   r   r   rx   r~   r.   r   __classcell__)rh   s   @rT   r[   r[   l   s   " "D "
C 4a 3 8HoEVX\E\<]3^ 
# 2_  =/SWBW9X0Y 
 (OK\^bKbBc9d !&9 !d38n !   D  @_ @QU @3 O 3  3 rV   r[   c                   j    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
Zdee	e
f   fdZy	)ra   )init_forbid_extra
init_typedwarn_required_dynamic_aliaseswarn_untyped_fieldsr   r   r   r   r   r   r^   rJ   Nc                    |j                   y t        |j                         }|q|j                  di       j                  di       }| j                  D ]?  }|j                  |d      }t	        |t
              st        d|       t        | ||       A y t               }|j                  |j                          | j                  D ]'  }|j                  t        |d      }t        | ||       ) y )NtoolrG   Fz/Configuration value must be a boolean for key: )fallback)config_file
parse_tomlget	__slots__rt   bool
ValueErrorsetattrr   read
getbooleanCONFIGFILE_KEY)rg   r^   toml_configconfigkeysettingrb   s          rT   rf   zPydanticPluginConfig.__init__   s    & !4!45" __VR044_bIF~~ **S%0!'40$'VWZV[%\]]c7+	 & )NMw223~~'22>3QV2Wc7+ &rV   c                 V    | j                   D ci c]  }|t        | |       c}S c c}w r`   )r   r   )rg   r   s     rT   rc   zPydanticPluginConfig.to_data  s*    37>>B>CWT3''>BBBs   &)r   r   r   r   r   __annotations__r+   rf   r   r   r   rc   r   rV   rT   ra   ra      sR    I #''##, ,D ,&Cc3h CrV   ra   r   c                    | j                   }t        |t              r|j                  }t        |t              r't        |j
                  t              r|j
                  }n]t        |t              r|}nJd| d|j                  j                   d}t        || j                  | j                         | j                  S |j                   j                  j                  t              }|| j                  S |j                  di       j                  d      }|dur4t!        t#        |j                         | j                  | j                         | j                  S )z3
    Raise an error if orm_mode is not enabled
    z
ctx.type: 
 (of type )r   orm_modeT)r   rt   r=   itemr7   r   r8   rh   r   error_unexpected_behaviorr   r   r   metadatar   METADATA_KEYerror_from_ormget_name)r   ctx_type
model_typedetailpydantic_metadatar   s         rT   r   r     s   
 xxH(H%==(L)j9J9JH.U&&
	Hh	'
hZz(2D2D2M2M1NaP!&#''3;;?&&&"0044\B &&& $$Xr266zBHtx
0#''3;;G"""rV   c                      e Zd ZU h dZee   ed<   dededdfdZ	d&dZ
d&d	Zd'dZdd
ded   fdZded   dd
deddfdZded   ddfdZded   deddfdZdeded
   fdZededededefd       Zedee   defd       Zededeee   ef   fd       Zded   ded ed!edee   f
d"Zded   dd
defd#Z eded   d$edefd%       Z!y)(r   >   extrafrozenr   allow_mutationalias_generatorallow_population_by_field_nametracked_config_fieldsr   rb   rJ   Nc                      || _         || _        y r`   )_ctxrb   )rg   r   rb   s      rT   rf   z!PydanticModelTransformer.__init__)  s    	*rV   c                 .   | j                   }|j                  j                  }| j                          | j	                         }| j                  |      }t        d |j                  dd D              }| j                  |||       | j                  |       | j                  ||j                  du xs |j                  du        |D ci c]  }|j                  |j                          c}|j                         d|j                   t"        <   yc c}w )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              3   @   K   | ]  }t        |      t        k(    y wr`   )rl   BASESETTINGS_FULLNAMErn   s     rT   rq   z5PydanticModelTransformer.transform.<locals>.<genexpr>=  s     `R_$,t,0EER_rr   NFT)r   )fieldsr   )r   r   r   adjust_validator_signaturescollect_configcollect_fieldsrv   rw   add_initializeradd_construct_method
set_frozenr   r   name	serializeset_values_dictr   r   )rg   r   r   r   r   is_settingsfields          rT   r   z"PydanticModelTransformer.transform-  s     iiww||((*$$&$$V,`RVRZRZ[^\^R_``VV[9!!&)v'<'<'E'^Z^I^_BHI&uzz5??#44&I,,.'
l#Is   
"Dc                    | j                   j                  j                  j                  j	                         D ]  \  }}t        |j                  t              s!|j                  j                  d   }t        |t              sKt        |j                  t              sf|j                  j                  t         dk(  sd|j                  j                  _         y)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   rt   ru   r   original_decoratorsr   calleer    ri   
_NAMESPACEfuncis_class)rg   r   rz   	first_decs       rT   r   z4PydanticModelTransformer.adjust_validator_signaturesF  s     ++11779ID##((I.HH88;	y(3"9#3#3X>!((11
|C^5__-1CHHMM* :rV   ModelConfigDatac                     | j                   }|j                  }t               }|j                  j                  D ]  }t        |t              s|j                  dk(  s$|j                  j                  D ]3  }t        |t              s|j                  | j                  |             5 |j                  s}|j                  r| j                  j                  st        |j                   |        |j"                  j$                  dd D ]  }t&        |j(                  vr|j                   j+                  t-        t/        |                   |j(                  t&           d   j1                         D ]  \  }}|j3                  ||         |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bodyrt   r   r   r   updateget_config_updatehas_alias_generatorr   rb   r   error_required_dynamic_aliasesr   r   rw   r   r   add_plugin_dependencyr5   rl   r   
setdefault)	rg   r   r   r   stmtsubstmtr   r   values	            rT   r   z'PydanticModelTransformer.collect_configX  s6    iigg "HHMMDdH-yyH$#yy~~G%g~> MM$"8"8"AB  .
 .."AA**HH2377DA " HHLL$D4==0 GG))*?T@R*ST#}}\:8DJJLe!!$.  M % rV   model_configPydanticModelFieldc                    | j                   }| j                   j                  }g }t               }|j                  j                  D ]  }t        |t              s|j                  d   }t        |t              rt        |j                        sJ|j                  s,| j                  j                  rt        |j                  |       |j                   j"                  j%                  |j                        }||j&                  }	t        |	t(              rt        |	t*              s|	j,                  r| j/                  |||      }
| j1                  |      \  }}|r8|j2                  s,| j                  j4                  rt7        |j                  |       |j9                  t;        |j                  |
|||j<                  |j>                               |jA                  |j                          |jC                         }|j                   jD                  dd D ]  }tF        |jH                  vrg }|j                  jK                  tM        tO        |                   |jH                  tF           d   jQ                         D ]q  \  }|vr9t:        jS                  ||      }|jA                         |j9                  |       Cfd|D        \  }|jU                  |       |j9                  |       s ||z   } |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   B   K   | ]  }|j                   k(  s|  y wr`   )r   )ro   ar   s     rT   rq   z:PydanticModelTransformer.collect_fields.<locals>.<genexpr>  s     H:a4:s   )+r   r   setr  r  rt   r   lvaluesr    rE   r   
new_syntaxrb   r   error_untyped_fieldsr   r   r   r   ru   r"   r*   is_classvarget_is_requiredget_alias_infor   r   r  appendr  r  r  addcopyrw   r   r   r  r5   rl   r   deserializeremove)rg   r  r   r   r   known_fieldsr  lhsrz   ru   r  r  r  
all_fieldsr   superclass_fieldsdatar   r   s                     @rT   r   z'PydanticModelTransformer.collect_fieldsw  sv   
 iiiimmuHHMMDdN3,,q/Cc8,N3884L??t'9'9'M'M$SWWd3
 ((..$$SXX.C{ 88D$0 dC(  ..sD#>K'+':':4'@$E$!$CC&&DD.sww=MM" +&7;;	 SXX&k "l [[]
HHLL$D4==0 "GG))*?T@R*ST"mmL9(CIIK
d|+.::4FE $$T*%,,U3H:HHU%%e,%,,U3 L +Z7J# %$ rV   r   r   r   c                    | j                   }| j                  j                  }|j                  du}|xs$ t	        |j
                  xr |j                         }| j                  ||||      }| j                  ||      sCt        d      }	|j                  t        |	t        t        j                        dt                     d|j                  j                   j"                  vrt%        |d|t'                      yy)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kwargsNrf   )r   rb   r   r   r   r
  get_field_argumentsshould_init_forbid_extrar*   r#  r   r6   r<   explicitr   r   r   r   
add_methodr9   )
rg   r   r   r   r   r/  r1  r0  init_argumentsvars
             rT   r   z(PydanticModelTransformer.add_initializer  s     ii""--99E	( 
D&&Tv/T/T+T-
 11%4FR[ 2 
 ,,VV<h-C!!(3	8J8J0KTS\"]^SWW\\///sJ
C 0rV   c           
         | j                   }|j                  j                  t         d|j                  j                  t         d      g      }t	        |t               g      }t        t        d|      |dt              }| j                  |ddd      }|g|z   }|j                  j                  t         d      }d	}|j                  j                  d
z   |z   }	t        dk\  rt        ||	t        dk\  r$t        d|j                  j                  dz         n
t        d      g |t        t         j"                              }
t%        ||	g |t        t         j"                              }nt'        ||	dg |      }
t%        ||	g |      }t)        t*        |      |j                  j,                  j.                  |<   t1        |
t              r|
}nt        |
      }t3        |d||||
d       y)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_PydanticBaseModelrM   )r      )r      r   z
.construct)	namespace	construct)return_type	self_typetvar_defis_classmethod)r   r   
named_typeBUILTINS_NAMEr@   r9   r   r*   r   r3  r   ri   r   r?   r>   r6   r<   from_omitted_genericsr)   rF   r&   r   r   r   rt   r6  )rg   r   r   set_stroptional_set_strfields_set_argumentconstruct_argumentsobj_typeself_tvar_nametvar_fullnametvdself_tvar_exprrA  s                rT   r   z-PydanticModelTransformer.add_construct_method  s    ii''$$d%;cgg>P>PTaSbbfQg>h=ij$gxz%:;&s=:J'KM]_celm"66vT^cot6u236II77%%w&?@-((3.?' *W4 bCGG,<,<|,KL"2	778C )	778N ^]BHMC(HUN-<T>-R>* c;'I#C(I!	
rV   r   c                    | j                   }|j                  j                  }|D ]6  }|j                  j	                  |j
                        }||j                  }t        |t              r||_	        Ot        |t              r1|j                  j                  s|j                  j                          	 t        |      }d| d|j"                   d}	t%        |	|j                  |j                         |j'                  |d      }||_        ||_	        t)        |      dz   t+        |      z   |_        t/        t0        |      |j                  t+        |      <   9 y# t        $ r t!        |      }Y w xY w)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)r1  rM   )r   r   r   r   r   r   ru   rt   r*   is_propertyr"   r   final_iterationdeferr   	TypeErrorreprrh   r   to_varrl   r   	_fullnamer&   r   )
rg   r   r   r   r   r   sym_noder8  var_strr   s
             rT   r   z#PydanticModelTransformer.set_frozen  s'    iiww||Ezz~~ejj1H#mmc3'&,CO_5cgg>U>UGGMMO,"%c(  /wiz#--PQRF-fcggswwGll45l9"( ,T 2S 88C= H,;D#,F

8C=)/  % ,"&s),s   6E  E76E7r  c                    |j                   d   }t        |t              r|j                  | j                  v sy|j                  dk(  rt        |j
                  t              r|j
                  j                  dk(  }n`t        |j
                  t              r|j
                  j                  dk(  }n,t        |j                  | j                  j                  |       yt        |      S |j                  dk(  rCd}t        |j
                  t              r|j
                  j                  dk(  rd	}t        |
      S t        |j
                  t              rF|j
                  j                  dv r.t        di |j                  |j
                  j                  dk(  iS t        |j                  | j                  j                  |       y)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.Falser]  r   )r  rt   r    r   r   rvaluer$   r  r   error_invalid_config_valuer   r   r  ri   )rg   r  r)  r\  r
  s        rT   r	  z*PydanticModelTransformer.get_config_update<  sL    ooa 3)chh$:T:T.T88w'..'2&~~33x?GNNJ7&~~22h>*388TYY]]GL"==88(("&'..(38O8OSb8b&+#"7JKKgnnh/GNN4K4KOr4r"\chh0G0G?0Z%[\\"388TYY]]GDrV   r   r  r)  c                    |j                   }t        |t              rBt        | j                  |j
                     j                        }t        j                  |       S t        |t              rt        |j                  t              r|j                  j                  t        k(  rt        |j                  |j                         D ]'  \  }}||dk(  r|j"                  t$        u c S |dk(  s' y t        | j                  |j
                     j                        }t        j                  |       S t        |t$              S )zg
        Returns a boolean indicating whether the field defined in `stmt` is a required field.
        r   r   F)r^  rt   r'   rA   r   r   r   r   type_has_implicit_defaultr   r   r#   ri   r   zipr   	arg_namesrh   r   )r   r  r)  expr
value_typer   r   s          rT   r!  z(PydanticModelTransformer.get_is_requiredX  s    
 {{dH%(#(();)@)@AJ/II*UUUdH%*T[['*Jt{{OcOcguOu !DNN;	T<49#4==L88,,  < )#(();)@)@AJ/II*UUU$--rV   type_c                     t        | t              ryt        | t              rt        d | j                  D              ryy)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              3   `   K   | ]&  }t        |t              xs t        |t               ( y wr`   )rt   r9   r6   )ro   r   s     rT   rq   zEPydanticModelTransformer.type_has_implicit_default.<locals>.<genexpr>|  s+      0
P[JtX&C*T7*CCP[s   ,.F)rt   r6   r@   rv   r   )rf  s    rT   ra  z2PydanticModelTransformer.type_has_implicit_defaultr  s=     eW%eY'C 0
PUP[P[0
 -
 rV   c                 t   | j                   }t        |t              ryt        |t              r7t        |j                  t
              r|j                  j                  t        k(  syt        |j                        D ];  \  }}|dk7  r|j                  |   }t        |t              r|j                  dfc S  y y)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^  rt   r'   r   r   r#   ri   r   	enumeraterc  r   r$   r  )r  rd  iarg_namer   s        rT   r"  z'PydanticModelTransformer.get_alias_info  s     {{dH% tX&:dkk7+KPTP[P[PdPdhvPv $T^^4KAx7"))A,C#w'yy%''! 5 rV   r/  r0  r1  c           	          | j                   j                  j                  }|D cg c]%  }|r|j                  s|j	                  ||||      ' }}|S c c}w )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.
        )r/  force_optionalr1  )r   r   r   r  to_argument)rg   r   r/  r0  r1  r   r   	argumentss           rT   r3  z,PydanticModelTransformer.get_field_arguments  sg     yy}}!!  
%"9"9 d%@R^gh 	 

 
s   *Ac                     |j                   s&| j                  |t        |j                              ry|j                  ry| 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\  rb   r   )rg   r   r   s      rT   r4  z1PydanticModelTransformer.should_init_forbid_extra  sI     44,,VT&:T:T5UV!!333rV   r
  c                 \    | D ]  }|j                   s y |r| D ]  }|j                   y y)z
        Returns whether any fields on the model have a "dynamic alias", i.e., an alias that cannot be
        determined during static analysis.
        TF)r  r  )r   r
  r   s      rT   rr  z1PydanticModelTransformer.is_dynamic_alias_present  s;     E&&  ;;&   rV   )rJ   N)rJ   r  )"r   r   r   r   r	   r   r   r-   ra   rf   r   r   r   r   r   r   r   r   r   r   r   r	  staticmethodr   r    r!  r;   ra  r
   r"  r   r3  r4  rr  r   rV   rT   r   r     s   '3s8 +O +<P +UY +
22$>R+< RFZA[ RhDd+?&@ DJ[ Djn Dsw D,8
40D+E 8
$ 8
tG&:!; GT Gd GB HEV<W 8 .X .^ .( .t . .2 *)= $    ^ hsmT6I0J  8/09=SWdh	h 4t4H/I 4Sd 4im 4 .B)C Z^ cg  rV   r   c                       e Zd Zdededee   dededefdZded	ed
e	fdZ
dededed	ed
ef
dZd
efdZededed
d fd       Zy)r  r   r  r  r  r  r  c                 X    || _         || _        || _        || _        || _        || _        y r`   r  )rg   r   r  r  r  r  r  s          rT   rf   zPydanticModelField.__init__  s0     	&
!2	rV   r   r1  rJ   c                     | j                   }|r| j                  | j                  }t        ||| j                      j                        S r`   )r   r  r*   r   )rg   r   r1  r   s       rT   rV  zPydanticModelField.to_var  s;    yy/::D4dii--..rV   r/  rn  c                    |r3|| j                      j                  || j                      j                  }nt        t        j                        }t        | j                  ||      |d |s| j                  st              S t              S )N)variabletype_annotationinitializerkind)
r   r   r6   r<   r5  r   rV  r  r   r   )rg   r   r/  rn  r1  rz  s         rT   ro  zPydanticModelField.to_argument  sz    T$))_))5"499o22O%i&8&89O[[y1+"08H8H	
 	
 OX	
 	
rV   c                     | j                   S r`   )__dict__)rg   s    rT   r   zPydanticModelField.serialize  s    }}rV   r,  c                      | di |S )Nr   r   )r   r   r,  s      rT   r&  zPydanticModelField.deserialize  s    {T{rV   N)r   r   r   r   r   r   rP   rf   r(   r*   rV  r   ro  r   r   classmethodr&  r   rV   rT   r  r    s    &*3;C=UYadnq/8 / / /

 

 

t 

X\ 

ai 

8  x x <P  rV   r  c                       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Zd	eeef   fd
Z	ded    d	dfdZ
deded	dfdZy)r  Nr\  r   r   r   r   r
  c                 X    || _         || _        || _        || _        || _        || _        y r`   )r\  r   r   r   r   r
  )rg   r\  r   r   r   r   r
  s          rT   rf   zModelConfigData.__init__  s2     ), .L+#6 rV   rJ   c                 p    | j                   j                         D ci c]  \  }}|	|| c}}S c c}}w r`   )r~  r   )rg   kvs      rT   r   zModelConfigData.set_values_dict  s5    !%!4!4!6H!6A!-1!6HHHs   
22r   c                 p    |y |j                         j                         D ]  \  }}t        | ||        y r`   )r   r   r   )rg   r   r  r  s       rT   r  zModelConfigData.update  s6    >**,224DAqD!Q 5rV   r   r  c                 8    t        | |      t        | ||       y y r`   )r   r   )rg   r   r  s      rT   r  zModelConfigData.setdefault  s     4%D#u% &rV   )NNNNNN)r   r   r   r   r   rf   r   r   r   r   r  r  r   rV   rT   r  r    s     (,)-!%#'9=.27tn7 !7 	7
 4.7 )17 &d^7 Ic3h I X&78  T  &c &# &$ &rV   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                 <    |j                  d|  d|t               y )N"z" does not have orm_mode=Truecode)fail	ERROR_ORM)r  r   r   s      rT   r   r     s    HHq9:G)HTrV   r   c                 <    |j                  d|  d|t               y )NzInvalid value for "Config.r  r  )r  ERROR_CONFIG)r   r   r   s      rT   r_  r_    s    HH)$q17HNrV   c                 4    | j                  d|t               y )Nz#Required dynamic aliases disallowedr  )r  ERROR_ALIASr   r   s     rT   r  r  "  s    HH2G+HNrV   r   c                 V    d}d|  d}|d| dz  }|j                  ||t               y )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!r  )r  ERROR_UNEXPECTED)r   r   r   linkfull_messages        rT   r   r   &  sA     DDLVHTVWL<TFB[\\LHH\7)9H:rV   c                 4    | j                  d|t               y )NzUntyped fields disallowedr  )r  ERROR_UNTYPEDr  s     rT   r  r  0  s    HH('HFrV   c                 4    | j                  d|t               y )Nz>Field default and default_factory cannot be specified togetherr  )r  ERROR_FIELD_DEFAULTSr  s     rT   r   r   4  s    HHMw]qHrrV   r   r@  rA  rB  rC  is_newc                 Z   | j                   j                  }||j                  v rn|j                  |   }	|	j                  rSt	        |	j
                  t              r9| j                   j                  j                  j                  |	j
                         |xs t        |      }|s|r0t        t        d      t        j                  |      dt              g}
n+|xs t        |      }t        t        d      |dt              g}
|
|z   }g g g }}}|D ]o  }|j                   sJ d       |j#                  |j                          |j#                  t%        |j&                               |j#                  |j(                         q | j*                  j-                  t.         d      }t1        |||||      }|r|g|_        t        ||t5        t7               g            }||_        t9        ||      |_        ||_        t?        |      dz   |z   |_         |jB                  |_!        ||j                  v r2tE        ||j                        }|j                  |   |j                  |<   |rud|_#        t        ||j:                        }||_        |j@                  |_         d|_$        tK        |tM        d      g|      }|jB                  |_!        tO        tP        |      }	ntO        tP        |      }	d|	_        |	|j                  |<   |jR                  j                  j                  j#                  |       y)	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	.functionrM   Tr  )*r   r   r   plugin_generatedrt   ru   r   r  r  r'  rB   r   r*   r=   make_normalizedr   rz  r#  r   ry  r|  r   rD  rE  r7   	variablesr   r!   r4   r   r  rl   rW  r  rC   is_decoratedrC  r   r    r&   r   defn)r   r   r   r@  rA  rB  rC  r  r   rz   firstr   rc  	arg_kindsr   function_type	signaturer   r_namer  decs                        rT   r6  r6  8  s     77<<D tzzjjJsxx$AGGLL$$SXX.0]40I#f+x'?'?	'JDRYZ[ 4t!4	#12ItWMN4<D&("b)yI""H$HH",,-#,,/0"	  GG&&-	'BCMY	9k=YI'j	4uhj\23DDI!)T2DI"DM!$'#-4DN		DI tzz-dDJJ?!ZZ-

6 dii nnx67;
 99dC(dD)CDJJtIINNt$rV   xc                 B    | j                   }t        |      r |       S |S zc
    Used for compatibility with mypy 0.740; can be dropped once support for 0.740 is dropped.
    )ri   callabler  fns     rT   rl   rl     s      
B|tIrV   c                 B    | j                   }t        |      r |       S |S r  )r   r  r  s     rT   r   r     s      
B|tIrV   r   c                 B   | j                  d      sy d}t        j                  dk\  rdd l}n	 dd l}t        | |      5 }|j                  |      cd d d        S # t
        $ r0 d}	 dd l}n%# t
        $ r dd l}|j                  d       Y Y y w xY wY _w xY w# 1 sw Y   y xY w)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  rfs        rT   r   r     s    (I
7"	! 
k9	%zz"~ 
&	%  		I$ jk	 %			 
&	%s@   A BB%A*)B*BBBBBB)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/   r0   r1   r2   mypy.pluginsr3   mypy.semanalr4   mypy.server.triggerr5   
mypy.typesr6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   mypy.typevarsrB   	mypy.utilrC   mypy.versionrD   mypy_versionpydantic.v1.utilsrE   rF   r  r   r   r   r   rm   r   r}   r   r   r   rP   rU   r   rE  r\   r[   ra   r   r   r  r  r  r  r  r  r  r  r   r_  r  r   r  r   r   r6  rl   r   r   r   rV   rT   <module>r     s   
 % ] ] ] %       > !   % * 5    ( 2 4 ,5%
 !'cr]
"|?3 %,&@A (\)=> <}-"|#9: A Ac3h A (5 0H<
. C 0 r V r j"C "CJ#= #T #2l l^" "J& &> n&=zJ	*,BJO(*DjQ24I:V *,F
S !13KZX Us U)? U' UVZ UOS O/N OY` Oei OO(G ORY O^b O;;24SST;_f;	;G= G GTX Gs5K sV] sbf s !%%) P%	P%
P% x.P% 	P%
 ~P% z"P% P% P% 
P%fE(J./ C h
*+  C HT#s(^$< m  5445s   H# #H21H2