1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
U
¸ý°dI*ã@sðddlmZddlmZddlmZddlmZddlmZddlmZddlm    Z    ddlm
Z
dd    lm Z dd
lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddl"m#Z#ddl"m$Z$dd l%m&Z&dd!l%m'Z'd"d#d$d%d&d'œd(d)„Z(d"d#d%d&d*œd+d,„Z)d#d-d.d/d/d&d0œd1d2„Z*d"d#d%d&d*œd3d4„Z+d#d"d5d5d&d6œd7d8„Z,d9S):é)Ú annotations)ÚList)ÚOptional)ÚUnion)Ú ARG_NAMED_OPT)ÚArgument)ÚAssignmentStmt)ÚCallExpr)ÚClassDef)ÚMDEF)Ú
MemberExpr)ÚNameExpr)ÚRefExpr)ÚStrExpr)ÚSymbolTableNode)ÚTempNode)ÚTypeInfo)ÚVar)ÚSemanticAnalyzerPluginInterface)Úadd_method_to_class)ÚAnyType)Úget_proper_type)ÚInstance)ÚNoneTyp)Ú
ProperType)Ú    TypeOfAny)Ú UnboundType)Ú    UnionTypeé)Úinfer)Úutil)Úexpr_to_mapped_constructor)ÚNAMED_TYPE_SQLA_MAPPEDr
rzUnion[NameExpr, StrExpr]zList[util.SQLAlchemyAttribute]ÚNone)ÚclsÚapiÚitemÚ
attributesÚreturnc    Csðt|tƒr|j}nt|tƒr$|j}ndS|jjD]2}t|tƒr0t|jdtƒr0|jdj|kr0q|q0t     
|d|›|¡dS|j dkr˜t     
|d|¡dSt |j ƒ}t|t ttfƒs¶t‚| t    j||j|j||jd¡t|||jd|dƒdS)NrzCan't find mapped attribute zBStatement linked from _mypy_mapped_attrs has no typing information)ÚnameÚlineÚcolumnÚtypÚinfo)Ú
isinstancer r)rÚvalueÚdefsÚbodyrÚlvaluesr ZfailÚtyperrrrÚAssertionErrorÚappendZSQLAlchemyAttributer*r+r-Úapply_type_to_mapped_statement)r$r%r&r'r)ÚstmtÚleft_hand_explicit_type©r9úPd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/ext/mypy/apply.pyÚapply_mypy_mapped_attr-sV
 
 ÿþý
ü
ÿûÿ
ÿr;)r$r%r'r(c
    CsÌdd„|Dƒ}d}|jjD]–}t|tƒrt|jdtƒr|jdj|krt|jdjtƒr|jdj}||jdjj    }t
|j    ƒ}t|t ƒrxt|t ƒsxt|j t ƒrxt|j jtƒrxt|j jjtƒrx|j jjjdk    rx|j jjjjtkrx|j jjdkrxt|j jdt ƒrxt|j jdjtƒrxt |||||j jdj¡}    |    dk    rxt|    t ƒsx|    }|||jdj_    d}t|j    tƒr”|j    j    jtkr|dk    s¢t‚| t|g¡|_    q|rÈt |j|¡dS)zlFor multiple class passes, re-apply our left-hand side types as mypy
    seems to reset them in place.
 
    cSsi|] }|j|“qSr9)r)©Ú.0Úattrr9r9r:Ú
<dictcomp>ksz4re_apply_declarative_assignments.<locals>.<dictcomp>FrNZ_empty_constructorT)r0r1r.rr2r r)Únoderr3rrÚrvaluer    Zcalleer ÚexprÚfullnamer"ÚargsrrZ#infer_type_from_right_hand_nameexprrr4Ú
named_typer Zset_mapped_attributesr-)
r$r%r'Zmapped_attr_lookupZupdate_cls_metadatar7Ú    left_nodeÚpython_type_for_typeZleft_node_proper_typeZnew_python_type_for_typer9r9r:Ú re_apply_declarative_assignmentsbs†    ÿþýü 
ÿ
ÿþ
ü ûúù ÿø
ö õ ô ûÿ
ÿþ
ÿ
ÿ þÿrHrr zOptional[ProperType])r%r7Úlvaluer8rGr(cCs†|j}t|tƒst‚|dk    r4d|_| t|g¡|_n*d|_| t|dkrTtt    j
ƒgn|g¡|_t |j ƒ|_ |jdk    r‚|dk    r‚||_dS)aµApply the Mapped[<type>] annotation and right hand object to a
    declarative assignment statement.
 
    This converts a Python declarative class statement such as::
 
        class User(Base):
            # ...
 
            attrname = Column(Integer)
 
    To one that describes the final Python behavior to Mypy::
 
        class User(Base):
            # ...
 
            attrname : Mapped[Optional[int]] = <meaningless temp node>
 
    NF) r@r.rr4Zis_inferred_defrEr"r3rrÚ special_formr!rA)r%r7rIr8rGrFr9r9r:r6¹s$ÿÿü r6c     Cs&t ||¡}|dkrdSt |¡}d|jkrè|sèdd„|Dƒ}|jdd…D]@}d|jkr\qLt ||¡}|dkrrqL|D]}| |j|j    ¡qvqLg}    | 
¡D]:\}
} | dkr´t t j ƒ} |     tt|
| ƒ| t| ƒtd¡qšt||d|    tƒƒd    |jkrt |¡rt||d
d    ƒ|s"t||d d ƒdS) zCApply __init__, __table__ and other attributes to the mapped class.NÚ__init__cSsi|]}|j|j“qSr9)r)r3r<r9r9r:r?
sz1add_additional_orm_attributes.<locals>.<dictcomp>réÿÿÿÿZ
sqlalchemy)ÚvariableZtype_annotationZ initializerÚkindZ    __table__zsqlalchemy.sql.schema.Tablezsqlalchemy.orm.mapper.MapperZ
__mapper__)r Z info_for_clsZ get_is_baseÚnamesÚmroÚmetadataZget_mapped_attributesÚ
setdefaultr)r3ÚitemsrrrJr5rrrrrrZ get_has_tableÚ _apply_placeholder_attr_to_class) r$r%r'r-Zis_baseZmapped_attr_namesÚbaseZbase_cls_attributesr>Ú    argumentsr)r,r9r9r:Úadd_additional_orm_attributesûsR 
 
 
üÿ    ÿÿrWÚstr)r%r$Úqualified_nameÚattrnamer(cCsr| |¡}|r,t|jtƒst‚t|jgƒ}n
ttjƒ}t    |ƒ}|j
d||_ |j |_ ||_ tt|ƒ|j j|<dS)NÚ.)Zlookup_fully_qualified_or_noner.r@rr4rrrrJrrCZ    _fullnamer-r3rr rO)r%r$rYrZÚsymÚtype_Úvarr9r9r:rT0s
 
rTN)-Ú
__future__rÚtypingrrrZ
mypy.nodesrrrr    r
r r r rrrrrrZ mypy.pluginrZmypy.plugins.commonrZ
mypy.typesrrrrrrrrÚrr rOr!r"r;rHr6rWrTr9r9r9r:Ú<module>sH                                5WB5