Xj+dZddlmZddlZddlmZddlmZddlm Z m Z ddl m Z ddl mZmZdd lmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm 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/m0Z0dd l1m2Z2dd l3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:dd l;mZ>ddl?m@Z@ddlAmBZBddlCmDZDddlEmFZFddlGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQddlRmSZSddlTmUZUddlVmWZXddlYmZZZddl[m\Z\dZ]dZ^dZ_dZ`dZadZbdZcdZdd Zed!Zfhd"Zgegd#hz Zhe\eXZid$Zjd%ZWdLd&ZkGd'd(e8ZlGd)d*ZmdMd+ZnGd,d-ZoGd.d/ZpGd0d1ZqGd2d3eDZrGd4d5ZsdNd6Zte d7d8d9Zue d:d;d9Zve dd?d9Zxe d@dAd9Zye d@dBd9Zze d@dCd9Z{dOdDZ|dPdEZ}dQdFZ~ dRdGZdQdHZdSdIZ dT dUdJZdVdKZy)Wz^This module includes classes and functions designed specifically for use with the mypy plugin.) annotationsN)Iterator) ConfigParser)AnyCallable) ErrorCode) expand_typeexpand_type_by_instance) ARG_NAMED ARG_NAMED_OPTARG_OPTARG_POS ARG_STAR2 INVARIANTMDEFArgumentAssignmentStmtBlockCallExprClassDefContext DecoratorDictExpr EllipsisExpr ExpressionFuncDefIfStmtJsonDict MemberExprNameExprPassStmtPlaceholderNodeRefExpr StatementStrExprSymbolTableNodeTempNode TypeAliasTypeInfoVar)Options)CheckerPluginInterfaceClassDefContextDynamicClassDefContext MethodContextPluginReportConfigContextSemanticAnalyzerPluginInterface)deserialize_and_fixup_type)set_callable_name)make_wildcard_trigger)state)TypeTranslator)map_type_from_supertype) AnyType CallableTypeInstanceNoneTypeType TypeOfAnyTypeType TypeVarType UnionTypeget_proper_type) fill_typevars)get_unique_redefinition_name) __version__)_fields)parse_mypy_version pydantic-mypyzpydantic-mypy-metadatazpydantic.main.BaseModelzpydantic.main.create_modelz#pydantic_settings.main.BaseSettingszpydantic.root_model.RootModelz5pydantic._internal._model_construction.ModelMetaclasszpydantic.fields.Fieldzpydantic.dataclasses.dataclass.pydantic.functional_validators.model_validator>*pydantic.functional_serializers.serializer.pydantic.deprecated.class_validators.validator.pydantic.functional_validators.field_validator3pydantic.deprecated.class_validators.root_validatorrI0pydantic.functional_serializers.model_serializerrNbuiltinsctS)a!`version` is the mypy version string. We might want to use this to print a warning if the mypy version being used is newer, or especially older, than we expect (or need). Args: version: The mypy version string. Return: The Pydantic mypy plugin type. )PydanticPlugin)versions a/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/pydantic/mypy.pypluginrUos  cdeZdZdZd fd Zd dZd dZd dZddZddZ ddZ dd Z dd Z xZ S)rRzThe Pydantic mypy plugin.ct||_|jj|_t||yN)PydanticPluginConfig plugin_configto_data _plugin_datasuper__init__)selfoptions __class__s rTr_zPydanticPlugin.__init__s41': ..668 !rVc|j|}|rEt|jtr+|jj t r |j Sy)zUpdate Pydantic model class.N)lookup_fully_qualified isinstancenoder)has_baseBASEMODEL_FULLNAME$_pydantic_model_class_maker_callback)r`fullnamesyms rTget_base_class_hookz"PydanticPlugin.get_base_class_hooksD))(3 :chh1xx  !34@@@rVc.|tk(r |jSy)z,Update Pydantic `ModelMetaclass` definition.N)MODEL_METACLASS_FULLNAME)_pydantic_model_metaclass_marker_callbackr`rjs rTget_metaclass_hookz!PydanticPlugin.get_metaclass_hooks / /AA ArVc2|jdrtSy)z-Adjust return type of `from_orm` method call.z .from_ormN)endswithfrom_attributes_callbackrps rTget_method_hookzPydanticPlugin.get_method_hooks   [ )+ +rVc.|tk(r |jSy)zARecognize `create_model()` calls as dynamic BaseModel subclasses.N)CREATE_MODEL_FULLNAME_pydantic_create_model_callbackrps rTget_dynamic_class_hookz%PydanticPlugin.get_dynamic_class_hooks , ,77 7rVc|jS)zjReturn all plugin config data. Used by mypy to determine if cache needs to be discarded. )r])r`ctxs rTreport_config_dataz!PydanticPlugin.report_config_datas    rVct|j|j|j|j}|j yrY)PydanticModelTransformerclsreasonapir[ transform)r`r{ transformers rTriz3PydanticPlugin._pydantic_model_class_maker_callbacks0.sww CGGTM_M_` rVc|jjry|jjj}|sJdt |j ddrd|j _yy)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_transformrinfodeclared_metaclassgetattrtyper)r`r{info_metaclasss rTroz8PydanticPlugin._pydantic_model_metaclass_marker_callbacks^    7 7 88NNN~ >&&(BD I;?N   8 JrVc>t}t|jj|jjD]\}}|dk(s t |t s|j*t |jtr|jj}[t |jtsvt |jjts|jjjj}|jj|}|t |jts<|jjt}|t |jtsy|j}t|}t |tsJ|jj!|j"||jj$}|j&|_|jj)|j"t+t,|y)zFMake variables assigned from `create_model()` usable as types by mypy.__base__N)rhzipcall arg_namesargsrer#rfr)rjr*rr;rlookup_fully_qualified_or_nonerCbasic_new_typeinfonamelinemetaclass_typeadd_symbol_table_noder&r) r`r{ base_fullnamearg_namearg_exprbase_sym base_info base_instancers rTrxz.PydanticPlugin._pydantic_create_model_callbackst+ "%chh&8&8#((--"H E Hh:%*Xw*GHMMLehmmX6$,MM$:$:M s3 8==CUCUW_8`$,MM$6$6$;$;$D$DM  E7799-H  :hmmX#Fww==>PQHz(--'JMM %i0 -222ww))#((M388==Q'66 %%chhd0KLrVrar+returnNone)rjstrrz(Callable[[ClassDefContext], None] | None)rjrrz&Callable[[MethodContext], Type] | None)rjrrz/Callable[[DynamicClassDefContext], None] | None)r{r1rdict[str, Any])r{r-rr)r{r.rr)__name__ __module__ __qualname____doc__r_rlrqruryr|rirorx __classcell__rbs@rTrRrR~s5#"    !  @MrVrRcNeZdZUdZdZded<ded<ded<ded<d dZd d Zy ) rZaA Pydantic mypy plugin config holder. Attributes: init_forbid_extra: Whether to add a `**kwargs` at the end of the generated `__init__` signature. init_typed: Whether to annotate fields in the generated `__init__`. warn_required_dynamic_aliases: Whether to raise required dynamic aliases error. debug_dataclass_transform: Whether to not reset `dataclass_transform_spec` attribute of `ModelMetaclass` for testing purposes. )init_forbid_extra init_typedwarn_required_dynamic_aliasesrboolrrrrc|jyt|j}|q|jdijdi}|jD]?}|j|d}t |t st d|t|||Ayt}|j|j|jD]'}|jt|d}t|||)y)NtoolrHFz/Configuration value must be a boolean for key: )fallback) config_file parse_tomlget __slots__rer ValueErrorsetattrrread getbooleanCONFIGFILE_KEY)r`ra toml_configconfigkeysettingr[s rTr_zPydanticPluginConfig.__init__s    &  !4!45  " __VR044_bIF~~ , **S%0!'40$'VWZV[%\]]c7+  , )NM   w22 3~~ ,'22>3QV2Wc7+ ,rVcV|jDcic]}|t||c}Scc}w)z/Returns a dict of config names to their values.)rr)r`rs rTr\zPydanticPluginConfig.to_datas&37>>BCWT3''BBBs&Nrrr)rrrrr__annotations__r_r\rVrTrZrZs3I #''##,&CrVrZc |j}t|tr |j}t|tr't|j t r |j }n]t|t r|}nJd|d|jjd}t||j|j|jS|jjjt}| |jS|jj!t"s |jS|jdijd}|dur5t%|jj&|j|j|jS)z1Raise an error if from_attributes is not enabled.z ctx.type: z (of type )rfrom_attributesT)rrer?itemr:ret_typer;rbrerror_unexpected_behaviorrcontextdefault_return_typemetadatar METADATA_KEYrgrherror_from_attributesr)r{ctx_type model_typedetailpydantic_metadatars rTrtrts0xxH(H%==(L)j9J9JH.U&& Hh ' hZz(2D2D2M2M1NaP!&#''3;;?&&&"0044\B &&& ?? # #$6 7&&&'++Hb9==>OPOd"joo22CGGS[[I  " ""rVceZdZdZ d dZ d dZ d d dZ d ddZddZe ddZ ddZ y )PydanticModelFieldz5Based on mypy.plugins.dataclasses.DataclassAttribute.c ||_||_||_||_||_||_||_||_| |_| |_ yrY) ralias is_frozenhas_dynamic_alias has_defaultstrictrcolumnrr) r`rrrrrrrrrrs rTr_zPydanticModelField.__init__ sL  "!2&     rVc 4|j||||} |j|n |j} |s| r|j||d} nttj } t | | d|r tS|s |jr tStS)zABased on mypy.plugins.dataclasses.DataclassAttribute.to_argument.NT)include_root_type)variabletype_annotation initializerkind) to_varrr r9r>explicitrr rr r ) r` current_infotyped model_strictforce_optional use_aliasrforce_typevars_invariantis_root_model_rootrrrs rT to_argumentzPydanticModelField.to_argument8s;;|S)=UV!%!4$++ F"..|STX.YO%i&8&89O+!   $2T5E5E-   LU   rVcZ|rFt|jtr,|jj}t|_||_|j4|j jtj|jj5t|}t|tsJ|r-|jD]}t|tst|_ t|j|j jj |i}|rdt|trTt#|jr?|jdj} | |cdddSt%| |} t'|| g}|cdddS|jS#1swY|jSxYw)zABased on mypy.plugins.dataclasses.DataclassAttribute.expand_type.Nroot)rerr@ copy_modifiedrvariancer self_typer6strict_optional_setrastrict_optionalrCr;rr id is_root_modelr rA) r`rrrr modified_typefilled_with_typevarsarg expanded_type root_typeexpanded_root_types rTr zPydanticModelField.expand_typeUsn $ $))[1 $ 7 7 9 )2 &) 99 TYY%8%8%D **3;;+F+FG %'4\'B$!"6AAA+3885%c;7+4CL5!,DII 8K8K8N8NPd7e f $M8)LQ^_l_q_qQr!. 2 26 : ? ?I (,! % %"*AM)Z&$-}>P.Q$RM$' % %(yy) %(yys?FBF&FF*c|r|j |j}n |j}t||j|||S)zextrafrozenralias_generatorrpopulate_by_namevalidate_by_namevalidate_by_aliaszset[str]tracked_config_fieldsc<||_||_||_||_yrY)_cls_reason_apir[)r`rrrr[s rTr_z!PydanticModelTransformer.__init__s!   *rVc|jj}t|}|j}|j ||\}}||y|D]}|j y|j t}|j|||||j|||||j||j|jdu|j|Dcic]}|j|jc}|Dcic]}|j|jc}|j!d|j"t$<ycc}wcc}w)aConfigures the BaseModel subclass according to the plugin settings. In particular: * determines the model config and fields, * adds a fields-aware signature for the initializer and construct methods * freezes the class if frozen = True * stores the fields, config, and if the class is settings in the mypy metadata for access by subclasses FT)r)fields class_varsr)rrrcollect_configcollect_fields_and_class_varsrrgBASESETTINGS_FULLNAMEadd_initializeradd_model_construct_method set_frozenrradjust_decorator_signaturesrrget_values_dictrr) r`ris_a_root_modelrr!r"field is_settings class_vars rTrz"PydanticModelTransformer.transforms9yy~~'-$$&!??X >Z/ Ezz! mm$9:  VV[/J '' _U  &--42GH ((*CIIuzz5??#44IR\]Y9>>9+>+>+@@],,.'  l#  J]s "E "Ec&|jjjjD]}t |j t s|j jdt tsHt jtscjjtvsjjtk(r(tfdtj Drd|j j"_y)aWhen we decorate a function `f` with `pydantic.validator(...)`, `pydantic.field_validator` or `pydantic.serializer(...)`, mypy sees `f` as a regular method taking a `self` instance, even though pydantic internally wraps `f` with `classmethod` if necessary. Teach mypy this by marking any function whose outermost decorator is a `validator()`, `field_validator()` or `serializer()` call as a `classmethod`. rc3K|]<\}}j|dk(xr!t|txr|jdk(>yw)modeafterN)rrer%value).0ir first_decs rT zGPydanticModelTransformer.adjust_decorator_signatures..sO  &3&//2f<rCQXAYr^a^g^gkr^rr sAATN)rrnamesvaluesrerfroriginal_decoratorsrcalleer rj(IMPLICIT_CLASSMETHOD_DECORATOR_FULLNAMESMODEL_VALIDATOR_FULLNAMEany enumeraterfuncis_class)r`rkr6s @rTr)z4PydanticModelTransformer.adjust_decorator_signatures s99>>''..0 2C#((I.HH88; y(3"9#3#3X>!((115]]"((115MM *3INN*C .2CHHMM*# 2rVc |j}t}d}d}|jjD]-\}}|j ||}|sd}|j |/d}|j jD]}t|ttfst|tr"|jd} t| tr| jdk7r[t|jtrdt!|jj"|jj$D]+\} } |  |j |j | | d-nt|jt&r|jjD]A\} } t| t(s|j |j | j*| Cnt|tr|jdk7ro|j jD]h}t|ts|jd} t| ts4|j |j | j|jj|r|j,j/d|nd}|s|rR|rP|j0rD|j2s8|j4s,|j6j8rt;|j,||j<j>d dD]}t@|jBvr|j,jEtG|jH|jBt@d jD]\}}|jK|||S) zhCollects the values of the config attributes that are used by the plugin, accounting for parent classes.FTNr model_config) lax_extraConfigzYSpecifying config in two places is ambiguous, use either Config attribute or class kwargsr)&rModelConfigDatakeywordsitemsget_config_updateupdatedefsbodyrerrlvaluesr rrvaluerrrrrr%r3rfailhas_alias_generatorrrr[rerror_required_dynamic_aliasesrmrorradd_plugin_dependencyr5rj setdefault)r`rrhas_config_kwargshas_config_from_namespacerexpr config_datastmtlhsrrkey_expr value_exprsubstmtrr3s rTr#z'PydanticModelTransformer.collect_config'sii "!$)!,,,,. +JD$00t?$/ll1o!#x0CHH4Ndkk84),T[[-B-BDKKDTDT)U] ##+$ d&<& !//!,C%c84 MM$"8"87>>"RS T! o(, %M& -P  9..00F4K4K&&DD.tyy$?HHLL$ /D4==0 II + +,A$--,P Q#}}\:8DJJL / e!!$. /  / rVc|j}i}i}t|jjddD]|}t|j vr|j jt|j|j tdjD]\}}tj|||j } | j|j|j | ||<|jjj|} | sz| j st#| j t$t&fr|j j)d| j |j tdjD]\}}t*j|||<t-} t-} |j/|j0D]} |j3| ||}|| j4d}t#|t6sJt#|trS|r&|j8dk7rt;|j | r| j=|j8|||j8<t#|t*s| j=|j8|||j8<t?|jAt?|jAfS)zACollects the fields for the model, accounting for parent classes.rFr!z7BaseModel field may only be overridden by another fieldr"rr)!rreversedrrSrrrrTr5rjrIrrrr8rrfrer*r"rPrset%_get_assignment_statements_from_blockrL$collect_field_or_class_var_from_stmtrNr r error_extra_fields_on_root_modeladdlistr9)r`rCrr found_fieldsfound_class_varsrrrr,sym_nodecurrent_field_namescurrent_class_vars_namesrZ maybe_fieldr[s rTr$z6PydanticModelTransformer.collect_fields_and_class_varsssoii79 =?SXX\\!B/0 QD4==0 II + +,A$--,P Q"mmL9(CIIK  d*66tT499M 11#((DIIF%* T"88>>--d3 jQTVePf6gIINNQ   #mmL9,GMMO Q d)>)J)J4)P & Q5 Q<),-0U >>sxxH 9DCCD,XhiK",,q/Cc8, ,,+'9: SXX%74TYYE'++CHH5-8L*K)>?(,,SXX6-8 * 9"L'')*D1A1H1H1J,KKKrVc#K|jD](}|jr|j|Ed{*|j;|jjs$|j|jEd{yyy7N7 wrY)rMis_unreachablerc else_body)r`rZrMs rT,_get_assignment_statements_from_if_statementzEPydanticModelTransformer._get_assignment_statements_from_if_statements{II LD&&EEdKKK L >> %dnn.K.KAA$..Q Q Q/L %L Qs'BBBAB:B;BBc#K|jD]A}t|tr|t|ts)|j |Ed{Cy7wrY)rMrerrrq)r`blockrZs rTrcz>PydanticModelTransformer._get_assignment_statements_from_blocksNJJ SD$/ D&)LLTRRR  SSs5AA A Ac 4|j}|jd}t|tr.t j |j r|j dk(ry|jst|jtrt|jjtr_t|jjjtr1|jjjjtvry|j |vryt|j|y|jd}t|tsyt j |j r|j dk(ry|jj j#|j }|y|j$}t|t&ryt|t(r|jj+d|yt|t,sy|j.rt1|j St3|j4}t|t6r5|j4jdk(r|jj+d||j9|} |j;|} |j4|j<rw|j>rk|jjA|jd} | r| |_n:|jj+d |tCtDjF|_|j<r| rt1|j S|jI|\} } | rD|jJs8|jLs,|jNjPrtS|j||jU|}|jW||j |}tY|j | | | | ||jZ|j\||j S) a^Get pydantic model field from statement. Args: stmt: The statement. model_config: Configuration settings for the model. class_vars: ClassVars already known to be defined on the model. Returns: A pydantic model field if it could find the field in statement. Otherwise, `None`. rrCNzFType aliases inside BaseModel definitions are not supported at runtimezdataclasses.InitVarz%InitVar is not supported in BaseModelT)is_finalzGNeed type argument for Final[...] with non-literal default in BaseModel) rrrrrrrrrr)/rrNrer rFis_valid_field_namer new_syntaxrOrr;rjDECORATOR_FULLNAMESerror_untyped_fieldsrrr8rrfr"r(rPr* is_classvarrrBrr;get_has_default get_strictru is_inferredanalyze_simple_literal_typer9r> from_errorget_alias_inforrr[rrRis_field_frozen_infer_dataclass_attr_init_typerrr)r`rZrCr"rr[rkrf node_typerrrrrr init_types rTrdz=PydanticModelTransformer.collect_field_or_class_var_from_stmts%iill1o#x(0K0KCHH0UY\YaYaesYs4;;1t{{118<t{{1188(CKK&&--66:MM xx:% !D 1ll1o#x(**3884N8Rhhnn  * ;xx dO ,  dI & IINNX $$    (2 2$DII. i *y~~/F/FJ_/_ IINN7  **40 & 88  $2B2B))77 d7SC  ]$I$8$89 ==[(2 2#'#6#6t#<  !22l6S6S""@@ *499d ;((. 88chhM !/#;;  rVc8|j}|jr|St|j}t|ts|S|jj d}|r:t|j tr|jjd}|sJ|jr+tt|j|j|}nttjSt|tr7|jtttgk(rt!|j"d|S|j$j'd|jj(d||S|j$j'd|jj(d||S)zvInfer __init__ argument type for an attribute. In particular, possibly use the signature of __set__. __set__rPz(Unsupported signature for "__set__" in ""zUnsupported "__set__" in ")rimplicitrBrer;rrfrget_containing_type_infor8r9r> unannotatedr: arg_kindsrr arg_typesrrPr) r`rkrrdefaulttsetter super_info setter_types rTrz8PydanticModelTransformer._infer_dataclass_attr_init_typeNsG (( <<N CHH % !X&NI& &++w/VV< 3;3H3H3KQOOIINN%Maffkk]Z[#\^ef !;AFFKK=JGTrVc d|jjjvr.|jjjdjsy|jj }t |j}|jxs |j xr|jdu}t |jxr |j }|j|||||||d} |rf|jjtj } t#| t$sJd| jvr| jdj } t#| t&sJ| | j(| j(} t#| t*sJt-| j.D]\} }|"|j1ds|j1ds+|jj3| j4| }|,|dvr(|j7t9t:j<}t?||}| jAtC||dtD|jG||sCt?d }| jAtC|tIt:jJdtLtO|j|jd| tQ y) zAdds a fields-aware `__init__` method to the class. The added `__init__` will be annotated with types vs. all `Any` depending on the plugin settings. r_NFT)rrrequires_dynamic_aliasesrr-rr___)_cli_settings_source_build_sourceskwargs)r return_type))rrr8plugin_generatedr[rrrrrrrQget_field_argumentsrrdr%rfrer)rrr:r?r startswith anal_typeracceptChangeExplicitTypeOfAnyr>from_omitted_genericsr*appendrr should_init_forbid_extrar9rr add_methodr<)r`r!rr-rrrrrrbase_settings_nodebase_settings_init_node func_typearg_idxranalyzed_variable_typervars rTr&z(PydanticModelTransformer.add_initializerts -- -diinn6J6J:6V6g6g ""--FMM* 00KF4K4KLvQWQiQiqvQv #'(B(B(b6KbKbGb#c '' %%=#'%)(   !%!A!ABW!X!]!] 0(; ;;/555*<*B*B:*N*S*S'!"97CCC*6;R;W;W;c 7 < >>-6y7J7J-K_)#+x/B/B4/HPXPcPcdgPh$151D1DYEXEXY`Ea1b.1=(OC6L5R5R 7 8W8W X62$'x1G#H HX7MtU\$]^_",,VV<h-C KKgi.@.@&A4S T499dii$HJWrVc |jjtd|jjtdg}t|t g}t t d||dt}tj|jjj5|j|dt|jdd||}ddd|j||sCt d} j!t | t#t$j&dt(|r|gzn|gz}t+|j|j,d |t/|j,j0d y#1swYxYw) zAdds a fully typed `model_construct` classmethod to the class. Similar to the fields-aware __init__ method, but always uses the field names (not aliases), and does not treat settings fields as optional. z.setz.str _fields_setNTF)rrrrr-rrmodel_construct)rris_classmethod)r named_type BUILTINS_NAMErAr<rr*r r6rrarrrrrrr9r>rrrrrCr) r`r!rr-rset_stroptional_set_strfields_set_argumentrrs rTr'z3PydanticModelTransformer.add_model_construct_methodsY))&&-'= @T@TXeWffjUk@l?mn$gxz%:;&s=:J'KM]_celm  & &tyy'8'8'H'H I ++!&--0).'+,D ,,VV<h-C KKgi.@.@&A4S T/W>WIIOO% ll4l>"( $  3chh > '6tS'A 388$# BrVc||jvry|dk(rft|tr|jdk(}n:t|tr|j dk(}n|st ||j|yt|S|dk(r/d}t|tr|jdk(rd}t| St|tr(|jd vrtd i||jd k(iSt ||j|y) zDetermines the config update due to a single kwarg in the ConfigDict definition. Warns if a tracked config attribute is set to a value the plugin doesn't know how to interpret (e.g., an int) Nrforbid) forbid_extrarT builtins.NoneF)rQ) builtins.Truebuiltins.Falserr) rrer%r3rrerror_invalid_config_valuerrGr rj)r`rrrDrrQs rTrJz*PydanticModelTransformer.get_config_updates t11 1 7?#w'"yyH4 C,"xx83  /tTYYD" = = $ $"& #x(S\\_-L&+#"7JK K c8 $9\)\"MdCLLO,K%LM M"4C8rVc|j}t|tryt|trt|jt r|jj tk(rmt|j|jD]I\}}||dk(r|jtucS|dk(s't|txr|j dk( cSyt|t S)zUReturns a boolean indicating whether the field defined in `stmt` is a required field.Frdefault_factoryr)rOrer'rr;r#rjFIELD_FULLNAMErrrrbrr rZrXrrs rTr{z(PydanticModelTransformer.get_has_defaults{{ dH % dH %*T[['*Jt{{OcOcguOu !DNN; _ T<49#4== <<,, *3 9 ]cllo>]^^  _ dL111rVcl|j}t|trt|jtr~|jj t k(rat|j|jD]>\}}|dk7r t|tr"|j dk(ry|j dk(ryyy)zEReturns a the `strict` value of a field if defined, otherwise `None`.rrTrFN) rOrerr;r#rjrrrrr rs rTr|z#PydanticModelTransformer.get_strict's{{ dH %*T[['*Jt{{OcOcguOu DNN;  T8#c8,||6#)99$ rVc|j}t|tryt|tr7t|jt r|jj tk(syd|jvr)|j|jjd}n8d|jvr)|j|jjd}nyt|tr|jdfSy)aReturns a pair (alias, has_dynamic_alias), extracted from the declaration of the field defined in `stmt`. `has_dynamic_alias` is True if and only if an alias is provided, but not as a string literal. If `has_dynamic_alias` is True, `alias` will be None. )NFvalidation_aliasrF)NT) rOrer'rr;r#rjrrrindexr%r3)rZrXrs rTrz'PydanticModelTransformer.get_alias_info7s{{ dH % tX &:dkk7+KPTP[P[PdPdhvPv  /))DNN001CDEC  &))DNN009:C c7 #99e# #rVcv|j}t|tryt|tr7t|jt r|jj tk(syt|jD]<\}}|dk(s |j|}t|txr|j dk(cSy)alReturns whether the field is frozen, extracted from the declaration of the field defined in `stmt`. Note that this is only whether the field was declared to be frozen in a ` = Field(frozen=True)` sense; this does not determine whether the field is frozen because the entire model is frozen; that is handled separately. Frr) rOrer'rr;r#rjrr?rrr )rZrXr5rrs rTrz(PydanticModelTransformer.is_field_frozenUs{{ dH % tX &:dkk7+KPTP[P[PdPdhvPv$T^^4 UKAx8#iil!#x0TS\\_5TT UrVc |jj} |D cgc]H} |r | js8| j| |||xs|||j||xr| j dk(J} } | Scc} w)zHelper function used during the construction of the `__init__` and `model_construct` method signatures. Returns a list of mypy Argument instances for use in the generated signatures. r)rrrrrrr)rrrrrr) r`r!rrrrr-rrrr, argumentss rTrz,PydanticModelTransformer.get_field_argumentsnsyy~~   %"9"9   )7F;#II)A#0#IUZZ65I       sA A,c|js2|js&|j|t|jry|j ry|j jS)a@Indicates whether the generated `__init__` should get a `**kwargs` at the end of its signature. We disallow arbitrary kwargs if the extra config setting is "forbid", or if the plugin config says to, *unless* a required dynamic alias is present (since then we can't determine a valid signature). FT)rris_dynamic_alias_presentrrQrr[r)r`r!rs rTrz1PydanticModelTransformer.should_init_forbid_extrasQ ''6+B+B,,VT&:T:T5UV   !!333rVc\|D]}|jsy|r|D]}|jyy)zReturns whether any fields on the model have a "dynamic alias", i.e., an alias that cannot be determined during static analysis. TF)rr)r!rQr,s rTrz1PydanticModelTransformer.is_dynamic_alias_presentsE  E&&   ;;& rVN) rrrzExpression | Statementrr2r[rZrr)rr)rr)rrG)rCrGrrrzJtuple[list[PydanticModelField] | None, list[PydanticModelClassVar] | None])rZrrIterator[AssignmentStmt])rsrrr)rZrrCrGr"z dict[str, PydanticModelClassVar]rz1PydanticModelField | PydanticModelClassVar | None)rkr&rrrrrr ) r!list[PydanticModelField]rrGr-rrrrr)r!rrr2rrrrr )rrrrrDrrModelConfigData | None)rZrrr)rZrrr)rZrrztuple[str | None, bool])r!rrrrrrrrrr-rrrrrrlist[Argument])r!rrrGrr)r!rrQrrr)rrrrrrr_rr)r#r$rqrcrdrr&r'r(rJ staticmethodr{r|rrrrrrrVrTr~r~s '8  +  +' +- + , +  +"H26JXBL+BL<@BL SBLHRSG "G 2AG OoG :G R$L7X.7X8G7XVZ7Xko7X 7Xr& (&  &  &  &  & PB2!F22*  :B*/(    #' #' @ 4  rVr~c,eZdZdZdfd ZddZxZS)rzrrr)r`rs rT visit_anyz!ChangeExplicitTypeOfAny.visit_anys0 ==I.. .??t/@/@?A AHrV)rr rr)rr9rr=)rrrrr_rrrs@rTrrsFrVrc`eZdZdZ d ddZd dZd dZd dZy) rGz(Pydantic mypy plugin model config class.Nc t||_||_||_||_||_||_||_||_yrY)rrrrrrrQr) r`rrrrrrrQrs rTr_zModelConfigData.__init__sB) . 0!2 0#6  rVcp|jjDcic] \}}| || c}}Scc}}w)zReturns a dict of Pydantic model config names to their values. It includes the config if config value is not `None`. )__dict__rI)r`kvs rTr*zModelConfigData.get_values_dicts1 "&!4!4!6HA!-1HHHs 22cp|y|jjD]\}}t|||y)z$Update Pydantic model config values.N)r*rIr)r`rrrs rTrKzModelConfigData.updates; > **,224 DAq D!Q  rVc8t||t|||yy)zFSet default value for Pydantic model config if config value is `None`.N)rr)r`rr3s rTrUzModelConfigData.setdefaults 4  % D#u % &rV)NNNNNNNN)rrrrrrrrrrrrrQrrrr)rrrr)rrr3rrr)rrrrr_r*rKrUrrVrTrGrGs2%)"'+(,)-(,+/"!%  &  ' &)(I &rVrGc,|jtS)zXReturn whether the type info is a root model subclass (or the `RootModel` class itself).)rgROOT_MODEL_FULLNAME)rs rTrrs ==, --rVz pydantic-ormzInvalid from_attributes callPydanticzpydantic-configzInvalid config valuezpydantic-aliaszDynamic alias disallowedzpydantic-unexpectedzUnexpected behaviorzpydantic-fieldzUntyped field disallowedzInvalid Field defaultsz!Extra field on RootModel subclassc<|jd|d|ty)zCEmits an error when the model does not have `from_attributes=True`.rz$" does not have from_attributes=TruecodeN)rP ERROR_ORM) model_namerrs rTrrsHHq @ A7QZH[rVc<|jd|d|ty)z0Emits an error when the config value is invalid.zInvalid value for "Config.rrN)rP ERROR_CONFIG)rrrs rTrrsHH)$q 17HNrVc4|jd|ty)znEmits required dynamic aliases error. This will be called when `warn_required_dynamic_aliases=True`. z#Required dynamic aliases disallowedrN)rP ERROR_ALIASrrs rTrRrRs HH 2G+HNrVcVd}d|d}|d|dz }|j||ty)z Emits unexpected behavior error.z6https://github.com/pydantic/pydantic/issues/new/choosez7The pydantic mypy plugin ran into unexpected behavior:  z&Please consider reporting this bug at z so we can try to fix it!rN)rPERROR_UNEXPECTED)rrrlink full_messages rTrrsA DDLVHTVWL|j}||jvrd|j|} | jrIt| jt r/|j jj| jt|tr|jd} n|jdg} |r6|xstt|}ttd|dt dg} n+|xs t|}ttd|dt g} | |z}ggg}} } |D]p}|j"sJd| j%|j"| j%|j&j(|j%|j*rt-| || || |r|gnd}t ||t/t1g}||_t3|||_||_|j8dz|z|_|j<|_||jvr2t?||j}|j||j|<|rud|_ t||j4}||_|j:|_d|_!tE|tGd g|}|j<|_tItJ|} ntItJ|} d| _| |j|<|jLj jj%|y) zhVery closely related to `mypy.plugins.common.add_method_to_class`, with a few pydantic-specific changes.zbuiltins.functionrNT__pydantic_self__z"All arguments must be fully typed.) variablesrr )'rr8rrerfrrLrMremover2rnamed_generic_typer?rCrr*rrrrrrr:rr!r4rrArjrrrD is_decoratedrrr r&rdefn)rrrrrrtvar_defrrrk function_typefirstrrrr signaturer@r_namerdecs rTrrs 88D tzzjj   Jsxx$A HHMM  *#67':; ../BBG >-*=!> #f+y$FG4t!4 #12ItWMN 4r?r@rArB mypy.typevarsrC mypy.utilrD mypy.versionrE mypy_versionpydantic._internalrFpydantic.versionrGrrrhrwr%rrnrDATACLASS_FULLNAMEr=rxr<MYPY_VERSION_TUPLErrUrRrZrtrrr~rrGrrrrrrERROR_FIELD_DEFAULTSrrrrRrryrerrrrVrTr-sd" $% %@!!!!!!!!!D!+5,0   (24&/ ' .4=5R(5K,?BtAu+u(( 5   TMVTMn+C+C\#4PTPTf  2^ ^ B n (&(&V. n&Dj Q *,BJO (*DjQ 24I:V*,F S  !13KZX()9;^`jk\ O O; ;N;Y`; ;G o"#' U% AU% U% U%  U%  U%  U%!U%U% U%prV