U kf&@sddlmZddlZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddl#m$Z$ddl%m&Z&ddl%m'Z'dd l%m(Z(dd!l)m*Z*dd"l+m,Z,dd#l-m.Z.dd$l-m/Z/dd%l-m0Z0dd&l-m1Z1dd l-m Z dd'l-m2Z2dd(l-m3Z3dd)l-m4Z4e5d*d+ej67d,DZ8e8d-kZ9e d.eeefd/Z:Gd0d1d1Z;d2d3d4d5d6Zd?d@Z>d7d2d=d>dAdBZ?d7d9dCdDdEZ@d7d9dCdFdGZAd7d3dCdHdIZBd7d3dCdJdKZCd7d9dCdLdMZDd7d3dCdNdOZEd7dPdQdRdSdTZFdUdVd2dWdXdYZd7dZd9d[d\d]ZGdPd2d^d9d_d`daZHdbd2d2d2d9dcdddeZIe dfdgdhd2d9didjdkdlZJe dhd2dmdndjdodlZJddgdhd2dpd=djdqdlZJdrdsdtdudvZKdwdxdydzd{ZLdPdUdUd|d}d~ZMddPddddZNdUddddZOdS)) annotationsN)Any)Iterable)Iterator)List)Optional)overload)Tuple)Type)TypeVar)Union)version) format_type)CallExpr)ClassDef)CLASSDEF_NO_INFO)Context) Expression)FuncDef)IfStmt)JsonDict) MemberExpr)NameExpr) Statement)SymbolTableNode) TypeAlias)TypeInfo)Options)ClassDefContext)DynamicClassDefContext)SemanticAnalyzerPluginInterface)deserialize_and_fixup_type)map_type_from_supertype) CallableType)get_proper_type)Instance)NoneType) TypeVarType) UnboundType) UnionTypecCs g|]}td|rt|qS)z^\d+$)rematchint).0xr/H/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/ext/mypy/util.py 6s r1.) _TArgType)boundc@sZeZdZdddddddddZd d d d Zddd ddZedd dddddZdS)SQLAlchemyAttributestrr,zOptional[Type]rNone)namelinecolumntypinforeturncCs"||_||_||_||_||_dSN)r:r;r<typer>)selfr:r;r<r=r>r/r/r0__init__?s zSQLAlchemyAttribute.__init__r)r?cCs$|js t|j|j|jt|jdS)N)r:r;r<rA)rAAssertionErrorr:r;r<serialize_type)rBr/r/r0 serializeMs  zSQLAlchemyAttribute.serialize)sub_typer?cCs&t|jtsdSt|j||j|_dS)zxExpands type vars in the context of a subtype when an attribute is inherited from a generic super type. N) isinstancerAr'r"r>)rBrGr/r/r0expand_typevar_from_subtypeVs z/SQLAlchemyAttribute.expand_typevar_from_subtyper )r>dataapir?cCs,|}t|d|}|f||d|S)NrA)r=r>)copyr!pop)clsr>rJrKr=r/r/r0 deserialize_szSQLAlchemyAttribute.deserializeN)__name__ __module__ __qualname__rCrFrI classmethodrOr/r/r/r0r7>s   r7r8bool)r:r?cCsttd|S)Nz ^__.+?__$)rTr*r+)r:r/r/r0name_is_dunderksrUrrr9)r>keyrJr?cCs||jdi|<dSNZ sqlalchemymetadata setdefault)r>rVrJr/r/r0_set_info_metadataosr[z Optional[Any])r>rVr?cCs|jdi|dSrW)rYget)r>rVr/r/r0_get_info_metadatassr]cCs0|jr,|jD]}t||}|dk r |Sq dSr@)mror])r>rVbaserYr/r/r0_get_info_mro_metadataws    r`)r>r?cCs|jdidSrWrXr>r/r/r0establish_as_sqlalchemysrbcCst|dddSNis_baseTr[rar/r/r0 set_is_basesrfcCst|d}|dkSrcr]r>rdr/r/r0 get_is_bases ricCst|d}|dkSrc)r`rhr/r/r0has_declarative_bases rjcCst|dddSNZ has_tableTrerar/r/r0 set_has_tablesrlcCst|d}|dkSrkrgrhr/r/r0 get_has_tables rmr z#Optional[List[SQLAlchemyAttribute]])r>rKr?cCsJt|d}|dkrdSg}|D]&}t|||}||||q|S)Nmapped_attributes)r]r7rOrIappend)r>rKrn attributesrJattrr/r/r0get_mapped_attributess  rrr r)typ_optionsr?cCstrt||St|SdSr@)mypy_14_mypy_format_type)rsrtr/r/r0rs rzList[SQLAlchemyAttribute])r>rpr?cCst|ddd|DdS)NrncSsg|] }|qSr/)rF)r- attributer/r/r0r1sz)set_mapped_attributes..re)r>rpr/r/r0set_mapped_attributess  rxr)rKmsgctxr?cCsd|}|||S)NzQLAlchemy Mypy plugin] %s)fail)rKryrzr/r/r0r{sr{z.Union[ClassDefContext, DynamicClassDefContext])rzmodule symbol_nameasnamer?cCs8|jj|jjj}||kr4|jj|j|}|||<dSr@)rKmodulesZ cur_mod_idnames)rzr|r}r~module_globalsZ lookup_symr/r/r0 add_globals  r.) expr_typesrz#Optional[Union[CallExpr, NameExpr]])callexprr:rr?cCsdSr@r/rr:rr/r/r0get_callexpr_kwargsrz!Tuple[TypingType[_TArgType], ...]zOptional[_TArgType]cCsdSr@r/rr/r/r0rsz%Optional[Tuple[TypingType[Any], ...]]cCsTz|j|}Wntk r&YdSX|j|}t||dk rB|nttfrP|SdSr@) arg_namesindex ValueErrorargsrHrr)rr:rZarg_idxkwargr/r/r0rs zIterable[Statement]zIterator[Statement])stmtsr?ccsR|D]H}t|trFt|jdtrF|jdjdkrF|jdjEdHq|VqdS)Nrztyping.TYPE_CHECKING)rHrexprrfullnamebody)rstmtr/r/r0flatten_typecheckingsrrz#Optional[Union[Instance, TypeInfo]])calleer?cCst|ttfrt|jtrP|jjrLt|jjtrLt|jjj}t|t rL|SdSt|jt rxt|jj }t|t r|Snt|jt r|jSdSr@) rHrrnoderrAr#r$ret_typer%rtargetr)rrZ target_typer/r/r0type_for_callees      r)rKr=r?cst|ts|S|jdkr>ttfdd|jDtgS|j|}|dk rt|trt|j t r|j }t |fdd|jDS|SdS)zTake the UnboundType that we seem to get as the ret_type from a FuncDef and convert it into an Instance/TypeInfo kind of structure that seems to work as the left-hand type of an AssignmentStatement. rcsg|]}t|qSr/)unbound_to_instance)r-Ztyp_argrKr/r0r1+sz'unbound_to_instance..Ncs$g|]}t|trt|n|qSr/)rHr(r)r-argrr/r0r1;s ) rHr(r:rr)rr&lookup_qualifiedrrrr%)rKr=rZ bound_typer/rr0rs4     rrzOptional[TypeInfo])rNrKr?cCsD|jtkr>||j|}|dkr$dS|r4t|jts8t|jS|jSr@)r>rrr:rHrrrD)rNrKsymr/r/r0 info_for_clsHs rzUnion[str, JsonDict])r=r?cCs\z |WStk rYnXt|drBtdd|jD|_nt|drT|}|S)Nrcss$|]}t|dr|n|VqdS)resolve_string_annotationN)hasattrr)r-ar/r/r0 [s z!serialize_type..r)rF Exceptionrtuplerr)r=r/r/r0rEUs    rE)P __future__rr*typingrrrrrrr r Z TypingTyper r Zmypyr Z mypy.messagesrrvZ mypy.nodesrrrrrrrrrrrrrrZ mypy.optionsrZ mypy.pluginrrr Zmypy.plugins.commonr!Z mypy.typeopsr"Z mypy.typesr#r$r%r&r'r(r)r __version__splitZ_versrur5r7rUr[r]r`rbrfrirjrlrmrrrxr{rrrrrrrEr/r/r/r0s                                         -    2