SQLAlchemy 2.0.47__cp313-cp313t-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sqlalchemy/__init__.py +283 -0
- sqlalchemy/connectors/__init__.py +18 -0
- sqlalchemy/connectors/aioodbc.py +184 -0
- sqlalchemy/connectors/asyncio.py +429 -0
- sqlalchemy/connectors/pyodbc.py +250 -0
- sqlalchemy/cyextension/__init__.py +6 -0
- sqlalchemy/cyextension/collections.cp313t-win32.pyd +0 -0
- sqlalchemy/cyextension/collections.pyx +409 -0
- sqlalchemy/cyextension/immutabledict.cp313t-win32.pyd +0 -0
- sqlalchemy/cyextension/immutabledict.pxd +8 -0
- sqlalchemy/cyextension/immutabledict.pyx +133 -0
- sqlalchemy/cyextension/processors.cp313t-win32.pyd +0 -0
- sqlalchemy/cyextension/processors.pyx +68 -0
- sqlalchemy/cyextension/resultproxy.cp313t-win32.pyd +0 -0
- sqlalchemy/cyextension/resultproxy.pyx +102 -0
- sqlalchemy/cyextension/util.cp313t-win32.pyd +0 -0
- sqlalchemy/cyextension/util.pyx +90 -0
- sqlalchemy/dialects/__init__.py +62 -0
- sqlalchemy/dialects/_typing.py +30 -0
- sqlalchemy/dialects/mssql/__init__.py +88 -0
- sqlalchemy/dialects/mssql/aioodbc.py +63 -0
- sqlalchemy/dialects/mssql/base.py +4093 -0
- sqlalchemy/dialects/mssql/information_schema.py +285 -0
- sqlalchemy/dialects/mssql/json.py +129 -0
- sqlalchemy/dialects/mssql/provision.py +185 -0
- sqlalchemy/dialects/mssql/pymssql.py +126 -0
- sqlalchemy/dialects/mssql/pyodbc.py +760 -0
- sqlalchemy/dialects/mysql/__init__.py +104 -0
- sqlalchemy/dialects/mysql/aiomysql.py +250 -0
- sqlalchemy/dialects/mysql/asyncmy.py +231 -0
- sqlalchemy/dialects/mysql/base.py +3949 -0
- sqlalchemy/dialects/mysql/cymysql.py +106 -0
- sqlalchemy/dialects/mysql/dml.py +225 -0
- sqlalchemy/dialects/mysql/enumerated.py +282 -0
- sqlalchemy/dialects/mysql/expression.py +146 -0
- sqlalchemy/dialects/mysql/json.py +91 -0
- sqlalchemy/dialects/mysql/mariadb.py +72 -0
- sqlalchemy/dialects/mysql/mariadbconnector.py +322 -0
- sqlalchemy/dialects/mysql/mysqlconnector.py +302 -0
- sqlalchemy/dialects/mysql/mysqldb.py +314 -0
- sqlalchemy/dialects/mysql/provision.py +153 -0
- sqlalchemy/dialects/mysql/pymysql.py +158 -0
- sqlalchemy/dialects/mysql/pyodbc.py +157 -0
- sqlalchemy/dialects/mysql/reflection.py +727 -0
- sqlalchemy/dialects/mysql/reserved_words.py +570 -0
- sqlalchemy/dialects/mysql/types.py +835 -0
- sqlalchemy/dialects/oracle/__init__.py +81 -0
- sqlalchemy/dialects/oracle/base.py +3802 -0
- sqlalchemy/dialects/oracle/cx_oracle.py +1555 -0
- sqlalchemy/dialects/oracle/dictionary.py +507 -0
- sqlalchemy/dialects/oracle/oracledb.py +941 -0
- sqlalchemy/dialects/oracle/provision.py +297 -0
- sqlalchemy/dialects/oracle/types.py +316 -0
- sqlalchemy/dialects/oracle/vector.py +365 -0
- sqlalchemy/dialects/postgresql/__init__.py +167 -0
- sqlalchemy/dialects/postgresql/_psycopg_common.py +189 -0
- sqlalchemy/dialects/postgresql/array.py +519 -0
- sqlalchemy/dialects/postgresql/asyncpg.py +1284 -0
- sqlalchemy/dialects/postgresql/base.py +5378 -0
- sqlalchemy/dialects/postgresql/dml.py +339 -0
- sqlalchemy/dialects/postgresql/ext.py +540 -0
- sqlalchemy/dialects/postgresql/hstore.py +406 -0
- sqlalchemy/dialects/postgresql/json.py +404 -0
- sqlalchemy/dialects/postgresql/named_types.py +524 -0
- sqlalchemy/dialects/postgresql/operators.py +129 -0
- sqlalchemy/dialects/postgresql/pg8000.py +669 -0
- sqlalchemy/dialects/postgresql/pg_catalog.py +326 -0
- sqlalchemy/dialects/postgresql/provision.py +183 -0
- sqlalchemy/dialects/postgresql/psycopg.py +862 -0
- sqlalchemy/dialects/postgresql/psycopg2.py +892 -0
- sqlalchemy/dialects/postgresql/psycopg2cffi.py +61 -0
- sqlalchemy/dialects/postgresql/ranges.py +1031 -0
- sqlalchemy/dialects/postgresql/types.py +313 -0
- sqlalchemy/dialects/sqlite/__init__.py +57 -0
- sqlalchemy/dialects/sqlite/aiosqlite.py +482 -0
- sqlalchemy/dialects/sqlite/base.py +3056 -0
- sqlalchemy/dialects/sqlite/dml.py +263 -0
- sqlalchemy/dialects/sqlite/json.py +92 -0
- sqlalchemy/dialects/sqlite/provision.py +229 -0
- sqlalchemy/dialects/sqlite/pysqlcipher.py +157 -0
- sqlalchemy/dialects/sqlite/pysqlite.py +756 -0
- sqlalchemy/dialects/type_migration_guidelines.txt +145 -0
- sqlalchemy/engine/__init__.py +62 -0
- sqlalchemy/engine/_py_processors.py +136 -0
- sqlalchemy/engine/_py_row.py +128 -0
- sqlalchemy/engine/_py_util.py +74 -0
- sqlalchemy/engine/base.py +3390 -0
- sqlalchemy/engine/characteristics.py +155 -0
- sqlalchemy/engine/create.py +893 -0
- sqlalchemy/engine/cursor.py +2298 -0
- sqlalchemy/engine/default.py +2394 -0
- sqlalchemy/engine/events.py +965 -0
- sqlalchemy/engine/interfaces.py +3471 -0
- sqlalchemy/engine/mock.py +134 -0
- sqlalchemy/engine/processors.py +61 -0
- sqlalchemy/engine/reflection.py +2102 -0
- sqlalchemy/engine/result.py +2399 -0
- sqlalchemy/engine/row.py +400 -0
- sqlalchemy/engine/strategies.py +16 -0
- sqlalchemy/engine/url.py +924 -0
- sqlalchemy/engine/util.py +167 -0
- sqlalchemy/event/__init__.py +26 -0
- sqlalchemy/event/api.py +220 -0
- sqlalchemy/event/attr.py +676 -0
- sqlalchemy/event/base.py +472 -0
- sqlalchemy/event/legacy.py +258 -0
- sqlalchemy/event/registry.py +390 -0
- sqlalchemy/events.py +17 -0
- sqlalchemy/exc.py +832 -0
- sqlalchemy/ext/__init__.py +11 -0
- sqlalchemy/ext/associationproxy.py +2027 -0
- sqlalchemy/ext/asyncio/__init__.py +25 -0
- sqlalchemy/ext/asyncio/base.py +281 -0
- sqlalchemy/ext/asyncio/engine.py +1471 -0
- sqlalchemy/ext/asyncio/exc.py +21 -0
- sqlalchemy/ext/asyncio/result.py +965 -0
- sqlalchemy/ext/asyncio/scoping.py +1599 -0
- sqlalchemy/ext/asyncio/session.py +1947 -0
- sqlalchemy/ext/automap.py +1701 -0
- sqlalchemy/ext/baked.py +570 -0
- sqlalchemy/ext/compiler.py +600 -0
- sqlalchemy/ext/declarative/__init__.py +65 -0
- sqlalchemy/ext/declarative/extensions.py +564 -0
- sqlalchemy/ext/horizontal_shard.py +478 -0
- sqlalchemy/ext/hybrid.py +1535 -0
- sqlalchemy/ext/indexable.py +364 -0
- sqlalchemy/ext/instrumentation.py +450 -0
- sqlalchemy/ext/mutable.py +1085 -0
- sqlalchemy/ext/mypy/__init__.py +6 -0
- sqlalchemy/ext/mypy/apply.py +324 -0
- sqlalchemy/ext/mypy/decl_class.py +515 -0
- sqlalchemy/ext/mypy/infer.py +590 -0
- sqlalchemy/ext/mypy/names.py +335 -0
- sqlalchemy/ext/mypy/plugin.py +303 -0
- sqlalchemy/ext/mypy/util.py +357 -0
- sqlalchemy/ext/orderinglist.py +439 -0
- sqlalchemy/ext/serializer.py +185 -0
- sqlalchemy/future/__init__.py +16 -0
- sqlalchemy/future/engine.py +15 -0
- sqlalchemy/inspection.py +174 -0
- sqlalchemy/log.py +288 -0
- sqlalchemy/orm/__init__.py +171 -0
- sqlalchemy/orm/_orm_constructors.py +2661 -0
- sqlalchemy/orm/_typing.py +179 -0
- sqlalchemy/orm/attributes.py +2845 -0
- sqlalchemy/orm/base.py +971 -0
- sqlalchemy/orm/bulk_persistence.py +2135 -0
- sqlalchemy/orm/clsregistry.py +571 -0
- sqlalchemy/orm/collections.py +1627 -0
- sqlalchemy/orm/context.py +3334 -0
- sqlalchemy/orm/decl_api.py +2004 -0
- sqlalchemy/orm/decl_base.py +2192 -0
- sqlalchemy/orm/dependency.py +1302 -0
- sqlalchemy/orm/descriptor_props.py +1092 -0
- sqlalchemy/orm/dynamic.py +300 -0
- sqlalchemy/orm/evaluator.py +379 -0
- sqlalchemy/orm/events.py +3252 -0
- sqlalchemy/orm/exc.py +237 -0
- sqlalchemy/orm/identity.py +302 -0
- sqlalchemy/orm/instrumentation.py +754 -0
- sqlalchemy/orm/interfaces.py +1496 -0
- sqlalchemy/orm/loading.py +1686 -0
- sqlalchemy/orm/mapped_collection.py +557 -0
- sqlalchemy/orm/mapper.py +4444 -0
- sqlalchemy/orm/path_registry.py +809 -0
- sqlalchemy/orm/persistence.py +1788 -0
- sqlalchemy/orm/properties.py +935 -0
- sqlalchemy/orm/query.py +3459 -0
- sqlalchemy/orm/relationships.py +3508 -0
- sqlalchemy/orm/scoping.py +2148 -0
- sqlalchemy/orm/session.py +5280 -0
- sqlalchemy/orm/state.py +1168 -0
- sqlalchemy/orm/state_changes.py +196 -0
- sqlalchemy/orm/strategies.py +3470 -0
- sqlalchemy/orm/strategy_options.py +2568 -0
- sqlalchemy/orm/sync.py +164 -0
- sqlalchemy/orm/unitofwork.py +796 -0
- sqlalchemy/orm/util.py +2403 -0
- sqlalchemy/orm/writeonly.py +674 -0
- sqlalchemy/pool/__init__.py +44 -0
- sqlalchemy/pool/base.py +1524 -0
- sqlalchemy/pool/events.py +375 -0
- sqlalchemy/pool/impl.py +588 -0
- sqlalchemy/py.typed +0 -0
- sqlalchemy/schema.py +69 -0
- sqlalchemy/sql/__init__.py +145 -0
- sqlalchemy/sql/_dml_constructors.py +132 -0
- sqlalchemy/sql/_elements_constructors.py +1872 -0
- sqlalchemy/sql/_orm_types.py +20 -0
- sqlalchemy/sql/_py_util.py +75 -0
- sqlalchemy/sql/_selectable_constructors.py +763 -0
- sqlalchemy/sql/_typing.py +482 -0
- sqlalchemy/sql/annotation.py +587 -0
- sqlalchemy/sql/base.py +2293 -0
- sqlalchemy/sql/cache_key.py +1057 -0
- sqlalchemy/sql/coercions.py +1404 -0
- sqlalchemy/sql/compiler.py +8081 -0
- sqlalchemy/sql/crud.py +1752 -0
- sqlalchemy/sql/ddl.py +1444 -0
- sqlalchemy/sql/default_comparator.py +551 -0
- sqlalchemy/sql/dml.py +1850 -0
- sqlalchemy/sql/elements.py +5589 -0
- sqlalchemy/sql/events.py +458 -0
- sqlalchemy/sql/expression.py +159 -0
- sqlalchemy/sql/functions.py +2158 -0
- sqlalchemy/sql/lambdas.py +1442 -0
- sqlalchemy/sql/naming.py +209 -0
- sqlalchemy/sql/operators.py +2623 -0
- sqlalchemy/sql/roles.py +323 -0
- sqlalchemy/sql/schema.py +6222 -0
- sqlalchemy/sql/selectable.py +7265 -0
- sqlalchemy/sql/sqltypes.py +3930 -0
- sqlalchemy/sql/traversals.py +1024 -0
- sqlalchemy/sql/type_api.py +2368 -0
- sqlalchemy/sql/util.py +1485 -0
- sqlalchemy/sql/visitors.py +1164 -0
- sqlalchemy/testing/__init__.py +96 -0
- sqlalchemy/testing/assertions.py +994 -0
- sqlalchemy/testing/assertsql.py +520 -0
- sqlalchemy/testing/asyncio.py +135 -0
- sqlalchemy/testing/config.py +434 -0
- sqlalchemy/testing/engines.py +483 -0
- sqlalchemy/testing/entities.py +117 -0
- sqlalchemy/testing/exclusions.py +476 -0
- sqlalchemy/testing/fixtures/__init__.py +28 -0
- sqlalchemy/testing/fixtures/base.py +384 -0
- sqlalchemy/testing/fixtures/mypy.py +332 -0
- sqlalchemy/testing/fixtures/orm.py +227 -0
- sqlalchemy/testing/fixtures/sql.py +482 -0
- sqlalchemy/testing/pickleable.py +155 -0
- sqlalchemy/testing/plugin/__init__.py +6 -0
- sqlalchemy/testing/plugin/bootstrap.py +51 -0
- sqlalchemy/testing/plugin/plugin_base.py +828 -0
- sqlalchemy/testing/plugin/pytestplugin.py +892 -0
- sqlalchemy/testing/profiling.py +329 -0
- sqlalchemy/testing/provision.py +603 -0
- sqlalchemy/testing/requirements.py +1945 -0
- sqlalchemy/testing/schema.py +198 -0
- sqlalchemy/testing/suite/__init__.py +19 -0
- sqlalchemy/testing/suite/test_cte.py +237 -0
- sqlalchemy/testing/suite/test_ddl.py +389 -0
- sqlalchemy/testing/suite/test_deprecations.py +153 -0
- sqlalchemy/testing/suite/test_dialect.py +776 -0
- sqlalchemy/testing/suite/test_insert.py +630 -0
- sqlalchemy/testing/suite/test_reflection.py +3557 -0
- sqlalchemy/testing/suite/test_results.py +504 -0
- sqlalchemy/testing/suite/test_rowcount.py +258 -0
- sqlalchemy/testing/suite/test_select.py +2010 -0
- sqlalchemy/testing/suite/test_sequence.py +317 -0
- sqlalchemy/testing/suite/test_types.py +2147 -0
- sqlalchemy/testing/suite/test_unicode_ddl.py +189 -0
- sqlalchemy/testing/suite/test_update_delete.py +139 -0
- sqlalchemy/testing/util.py +535 -0
- sqlalchemy/testing/warnings.py +52 -0
- sqlalchemy/types.py +74 -0
- sqlalchemy/util/__init__.py +162 -0
- sqlalchemy/util/_collections.py +712 -0
- sqlalchemy/util/_concurrency_py3k.py +288 -0
- sqlalchemy/util/_has_cy.py +40 -0
- sqlalchemy/util/_py_collections.py +541 -0
- sqlalchemy/util/compat.py +421 -0
- sqlalchemy/util/concurrency.py +110 -0
- sqlalchemy/util/deprecations.py +401 -0
- sqlalchemy/util/langhelpers.py +2203 -0
- sqlalchemy/util/preloaded.py +150 -0
- sqlalchemy/util/queue.py +322 -0
- sqlalchemy/util/tool_support.py +201 -0
- sqlalchemy/util/topological.py +120 -0
- sqlalchemy/util/typing.py +734 -0
- sqlalchemy-2.0.47.dist-info/METADATA +243 -0
- sqlalchemy-2.0.47.dist-info/RECORD +274 -0
- sqlalchemy-2.0.47.dist-info/WHEEL +5 -0
- sqlalchemy-2.0.47.dist-info/licenses/LICENSE +19 -0
- sqlalchemy-2.0.47.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
# ext/mypy/names.py
|
|
2
|
+
# Copyright (C) 2021-2026 the SQLAlchemy authors and contributors
|
|
3
|
+
# <see AUTHORS file>
|
|
4
|
+
#
|
|
5
|
+
# This module is part of SQLAlchemy and is released under
|
|
6
|
+
# the MIT License: https://www.opensource.org/licenses/mit-license.php
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Dict
|
|
11
|
+
from typing import List
|
|
12
|
+
from typing import Optional
|
|
13
|
+
from typing import Set
|
|
14
|
+
from typing import Tuple
|
|
15
|
+
from typing import Union
|
|
16
|
+
|
|
17
|
+
from mypy.nodes import ARG_POS
|
|
18
|
+
from mypy.nodes import CallExpr
|
|
19
|
+
from mypy.nodes import ClassDef
|
|
20
|
+
from mypy.nodes import Decorator
|
|
21
|
+
from mypy.nodes import Expression
|
|
22
|
+
from mypy.nodes import FuncDef
|
|
23
|
+
from mypy.nodes import MemberExpr
|
|
24
|
+
from mypy.nodes import NameExpr
|
|
25
|
+
from mypy.nodes import OverloadedFuncDef
|
|
26
|
+
from mypy.nodes import SymbolNode
|
|
27
|
+
from mypy.nodes import TypeAlias
|
|
28
|
+
from mypy.nodes import TypeInfo
|
|
29
|
+
from mypy.plugin import SemanticAnalyzerPluginInterface
|
|
30
|
+
from mypy.types import CallableType
|
|
31
|
+
from mypy.types import get_proper_type
|
|
32
|
+
from mypy.types import Instance
|
|
33
|
+
from mypy.types import UnboundType
|
|
34
|
+
|
|
35
|
+
from ... import util
|
|
36
|
+
|
|
37
|
+
COLUMN: int = util.symbol("COLUMN")
|
|
38
|
+
RELATIONSHIP: int = util.symbol("RELATIONSHIP")
|
|
39
|
+
REGISTRY: int = util.symbol("REGISTRY")
|
|
40
|
+
COLUMN_PROPERTY: int = util.symbol("COLUMN_PROPERTY")
|
|
41
|
+
TYPEENGINE: int = util.symbol("TYPEENGNE")
|
|
42
|
+
MAPPED: int = util.symbol("MAPPED")
|
|
43
|
+
DECLARATIVE_BASE: int = util.symbol("DECLARATIVE_BASE")
|
|
44
|
+
DECLARATIVE_META: int = util.symbol("DECLARATIVE_META")
|
|
45
|
+
MAPPED_DECORATOR: int = util.symbol("MAPPED_DECORATOR")
|
|
46
|
+
SYNONYM_PROPERTY: int = util.symbol("SYNONYM_PROPERTY")
|
|
47
|
+
COMPOSITE_PROPERTY: int = util.symbol("COMPOSITE_PROPERTY")
|
|
48
|
+
DECLARED_ATTR: int = util.symbol("DECLARED_ATTR")
|
|
49
|
+
MAPPER_PROPERTY: int = util.symbol("MAPPER_PROPERTY")
|
|
50
|
+
AS_DECLARATIVE: int = util.symbol("AS_DECLARATIVE")
|
|
51
|
+
AS_DECLARATIVE_BASE: int = util.symbol("AS_DECLARATIVE_BASE")
|
|
52
|
+
DECLARATIVE_MIXIN: int = util.symbol("DECLARATIVE_MIXIN")
|
|
53
|
+
QUERY_EXPRESSION: int = util.symbol("QUERY_EXPRESSION")
|
|
54
|
+
|
|
55
|
+
# names that must succeed with mypy.api.named_type
|
|
56
|
+
NAMED_TYPE_BUILTINS_OBJECT = "builtins.object"
|
|
57
|
+
NAMED_TYPE_BUILTINS_STR = "builtins.str"
|
|
58
|
+
NAMED_TYPE_BUILTINS_LIST = "builtins.list"
|
|
59
|
+
NAMED_TYPE_SQLA_MAPPED = "sqlalchemy.orm.base.Mapped"
|
|
60
|
+
|
|
61
|
+
_RelFullNames = {
|
|
62
|
+
"sqlalchemy.orm.relationships.Relationship",
|
|
63
|
+
"sqlalchemy.orm.relationships.RelationshipProperty",
|
|
64
|
+
"sqlalchemy.orm.relationships._RelationshipDeclared",
|
|
65
|
+
"sqlalchemy.orm.Relationship",
|
|
66
|
+
"sqlalchemy.orm.RelationshipProperty",
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
_lookup: Dict[str, Tuple[int, Set[str]]] = {
|
|
70
|
+
"Column": (
|
|
71
|
+
COLUMN,
|
|
72
|
+
{
|
|
73
|
+
"sqlalchemy.sql.schema.Column",
|
|
74
|
+
"sqlalchemy.sql.Column",
|
|
75
|
+
},
|
|
76
|
+
),
|
|
77
|
+
"Relationship": (RELATIONSHIP, _RelFullNames),
|
|
78
|
+
"RelationshipProperty": (RELATIONSHIP, _RelFullNames),
|
|
79
|
+
"_RelationshipDeclared": (RELATIONSHIP, _RelFullNames),
|
|
80
|
+
"registry": (
|
|
81
|
+
REGISTRY,
|
|
82
|
+
{
|
|
83
|
+
"sqlalchemy.orm.decl_api.registry",
|
|
84
|
+
"sqlalchemy.orm.registry",
|
|
85
|
+
},
|
|
86
|
+
),
|
|
87
|
+
"ColumnProperty": (
|
|
88
|
+
COLUMN_PROPERTY,
|
|
89
|
+
{
|
|
90
|
+
"sqlalchemy.orm.properties.MappedSQLExpression",
|
|
91
|
+
"sqlalchemy.orm.MappedSQLExpression",
|
|
92
|
+
"sqlalchemy.orm.properties.ColumnProperty",
|
|
93
|
+
"sqlalchemy.orm.ColumnProperty",
|
|
94
|
+
},
|
|
95
|
+
),
|
|
96
|
+
"MappedSQLExpression": (
|
|
97
|
+
COLUMN_PROPERTY,
|
|
98
|
+
{
|
|
99
|
+
"sqlalchemy.orm.properties.MappedSQLExpression",
|
|
100
|
+
"sqlalchemy.orm.MappedSQLExpression",
|
|
101
|
+
"sqlalchemy.orm.properties.ColumnProperty",
|
|
102
|
+
"sqlalchemy.orm.ColumnProperty",
|
|
103
|
+
},
|
|
104
|
+
),
|
|
105
|
+
"Synonym": (
|
|
106
|
+
SYNONYM_PROPERTY,
|
|
107
|
+
{
|
|
108
|
+
"sqlalchemy.orm.descriptor_props.Synonym",
|
|
109
|
+
"sqlalchemy.orm.Synonym",
|
|
110
|
+
"sqlalchemy.orm.descriptor_props.SynonymProperty",
|
|
111
|
+
"sqlalchemy.orm.SynonymProperty",
|
|
112
|
+
},
|
|
113
|
+
),
|
|
114
|
+
"SynonymProperty": (
|
|
115
|
+
SYNONYM_PROPERTY,
|
|
116
|
+
{
|
|
117
|
+
"sqlalchemy.orm.descriptor_props.Synonym",
|
|
118
|
+
"sqlalchemy.orm.Synonym",
|
|
119
|
+
"sqlalchemy.orm.descriptor_props.SynonymProperty",
|
|
120
|
+
"sqlalchemy.orm.SynonymProperty",
|
|
121
|
+
},
|
|
122
|
+
),
|
|
123
|
+
"Composite": (
|
|
124
|
+
COMPOSITE_PROPERTY,
|
|
125
|
+
{
|
|
126
|
+
"sqlalchemy.orm.descriptor_props.Composite",
|
|
127
|
+
"sqlalchemy.orm.Composite",
|
|
128
|
+
"sqlalchemy.orm.descriptor_props.CompositeProperty",
|
|
129
|
+
"sqlalchemy.orm.CompositeProperty",
|
|
130
|
+
},
|
|
131
|
+
),
|
|
132
|
+
"CompositeProperty": (
|
|
133
|
+
COMPOSITE_PROPERTY,
|
|
134
|
+
{
|
|
135
|
+
"sqlalchemy.orm.descriptor_props.Composite",
|
|
136
|
+
"sqlalchemy.orm.Composite",
|
|
137
|
+
"sqlalchemy.orm.descriptor_props.CompositeProperty",
|
|
138
|
+
"sqlalchemy.orm.CompositeProperty",
|
|
139
|
+
},
|
|
140
|
+
),
|
|
141
|
+
"MapperProperty": (
|
|
142
|
+
MAPPER_PROPERTY,
|
|
143
|
+
{
|
|
144
|
+
"sqlalchemy.orm.interfaces.MapperProperty",
|
|
145
|
+
"sqlalchemy.orm.MapperProperty",
|
|
146
|
+
},
|
|
147
|
+
),
|
|
148
|
+
"TypeEngine": (TYPEENGINE, {"sqlalchemy.sql.type_api.TypeEngine"}),
|
|
149
|
+
"Mapped": (MAPPED, {NAMED_TYPE_SQLA_MAPPED}),
|
|
150
|
+
"declarative_base": (
|
|
151
|
+
DECLARATIVE_BASE,
|
|
152
|
+
{
|
|
153
|
+
"sqlalchemy.ext.declarative.declarative_base",
|
|
154
|
+
"sqlalchemy.orm.declarative_base",
|
|
155
|
+
"sqlalchemy.orm.decl_api.declarative_base",
|
|
156
|
+
},
|
|
157
|
+
),
|
|
158
|
+
"DeclarativeMeta": (
|
|
159
|
+
DECLARATIVE_META,
|
|
160
|
+
{
|
|
161
|
+
"sqlalchemy.ext.declarative.DeclarativeMeta",
|
|
162
|
+
"sqlalchemy.orm.DeclarativeMeta",
|
|
163
|
+
"sqlalchemy.orm.decl_api.DeclarativeMeta",
|
|
164
|
+
},
|
|
165
|
+
),
|
|
166
|
+
"mapped": (
|
|
167
|
+
MAPPED_DECORATOR,
|
|
168
|
+
{
|
|
169
|
+
"sqlalchemy.orm.decl_api.registry.mapped",
|
|
170
|
+
"sqlalchemy.orm.registry.mapped",
|
|
171
|
+
},
|
|
172
|
+
),
|
|
173
|
+
"as_declarative": (
|
|
174
|
+
AS_DECLARATIVE,
|
|
175
|
+
{
|
|
176
|
+
"sqlalchemy.ext.declarative.as_declarative",
|
|
177
|
+
"sqlalchemy.orm.decl_api.as_declarative",
|
|
178
|
+
"sqlalchemy.orm.as_declarative",
|
|
179
|
+
},
|
|
180
|
+
),
|
|
181
|
+
"as_declarative_base": (
|
|
182
|
+
AS_DECLARATIVE_BASE,
|
|
183
|
+
{
|
|
184
|
+
"sqlalchemy.orm.decl_api.registry.as_declarative_base",
|
|
185
|
+
"sqlalchemy.orm.registry.as_declarative_base",
|
|
186
|
+
},
|
|
187
|
+
),
|
|
188
|
+
"declared_attr": (
|
|
189
|
+
DECLARED_ATTR,
|
|
190
|
+
{
|
|
191
|
+
"sqlalchemy.orm.decl_api.declared_attr",
|
|
192
|
+
"sqlalchemy.orm.declared_attr",
|
|
193
|
+
},
|
|
194
|
+
),
|
|
195
|
+
"declarative_mixin": (
|
|
196
|
+
DECLARATIVE_MIXIN,
|
|
197
|
+
{
|
|
198
|
+
"sqlalchemy.orm.decl_api.declarative_mixin",
|
|
199
|
+
"sqlalchemy.orm.declarative_mixin",
|
|
200
|
+
},
|
|
201
|
+
),
|
|
202
|
+
"query_expression": (
|
|
203
|
+
QUERY_EXPRESSION,
|
|
204
|
+
{
|
|
205
|
+
"sqlalchemy.orm.query_expression",
|
|
206
|
+
"sqlalchemy.orm._orm_constructors.query_expression",
|
|
207
|
+
},
|
|
208
|
+
),
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def has_base_type_id(info: TypeInfo, type_id: int) -> bool:
|
|
213
|
+
for mr in info.mro:
|
|
214
|
+
check_type_id, fullnames = _lookup.get(mr.name, (None, None))
|
|
215
|
+
if check_type_id == type_id:
|
|
216
|
+
break
|
|
217
|
+
else:
|
|
218
|
+
return False
|
|
219
|
+
|
|
220
|
+
if fullnames is None:
|
|
221
|
+
return False
|
|
222
|
+
|
|
223
|
+
return mr.fullname in fullnames
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def mro_has_id(mro: List[TypeInfo], type_id: int) -> bool:
|
|
227
|
+
for mr in mro:
|
|
228
|
+
check_type_id, fullnames = _lookup.get(mr.name, (None, None))
|
|
229
|
+
if check_type_id == type_id:
|
|
230
|
+
break
|
|
231
|
+
else:
|
|
232
|
+
return False
|
|
233
|
+
|
|
234
|
+
if fullnames is None:
|
|
235
|
+
return False
|
|
236
|
+
|
|
237
|
+
return mr.fullname in fullnames
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def type_id_for_unbound_type(
|
|
241
|
+
type_: UnboundType, cls: ClassDef, api: SemanticAnalyzerPluginInterface
|
|
242
|
+
) -> Optional[int]:
|
|
243
|
+
sym = api.lookup_qualified(type_.name, type_)
|
|
244
|
+
if sym is not None:
|
|
245
|
+
if isinstance(sym.node, TypeAlias):
|
|
246
|
+
target_type = get_proper_type(sym.node.target)
|
|
247
|
+
if isinstance(target_type, Instance):
|
|
248
|
+
return type_id_for_named_node(target_type.type)
|
|
249
|
+
elif isinstance(sym.node, TypeInfo):
|
|
250
|
+
return type_id_for_named_node(sym.node)
|
|
251
|
+
|
|
252
|
+
return None
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def type_id_for_callee(callee: Expression) -> Optional[int]:
|
|
256
|
+
if isinstance(callee, (MemberExpr, NameExpr)):
|
|
257
|
+
if isinstance(callee.node, Decorator) and isinstance(
|
|
258
|
+
callee.node.func, FuncDef
|
|
259
|
+
):
|
|
260
|
+
if callee.node.func.type and isinstance(
|
|
261
|
+
callee.node.func.type, CallableType
|
|
262
|
+
):
|
|
263
|
+
ret_type = get_proper_type(callee.node.func.type.ret_type)
|
|
264
|
+
|
|
265
|
+
if isinstance(ret_type, Instance):
|
|
266
|
+
return type_id_for_fullname(ret_type.type.fullname)
|
|
267
|
+
|
|
268
|
+
return None
|
|
269
|
+
|
|
270
|
+
elif isinstance(callee.node, OverloadedFuncDef):
|
|
271
|
+
if (
|
|
272
|
+
callee.node.impl
|
|
273
|
+
and callee.node.impl.type
|
|
274
|
+
and isinstance(callee.node.impl.type, CallableType)
|
|
275
|
+
):
|
|
276
|
+
ret_type = get_proper_type(callee.node.impl.type.ret_type)
|
|
277
|
+
|
|
278
|
+
if isinstance(ret_type, Instance):
|
|
279
|
+
return type_id_for_fullname(ret_type.type.fullname)
|
|
280
|
+
|
|
281
|
+
return None
|
|
282
|
+
elif isinstance(callee.node, FuncDef):
|
|
283
|
+
if callee.node.type and isinstance(callee.node.type, CallableType):
|
|
284
|
+
ret_type = get_proper_type(callee.node.type.ret_type)
|
|
285
|
+
|
|
286
|
+
if isinstance(ret_type, Instance):
|
|
287
|
+
return type_id_for_fullname(ret_type.type.fullname)
|
|
288
|
+
|
|
289
|
+
return None
|
|
290
|
+
elif isinstance(callee.node, TypeAlias):
|
|
291
|
+
target_type = get_proper_type(callee.node.target)
|
|
292
|
+
if isinstance(target_type, Instance):
|
|
293
|
+
return type_id_for_fullname(target_type.type.fullname)
|
|
294
|
+
elif isinstance(callee.node, TypeInfo):
|
|
295
|
+
return type_id_for_named_node(callee)
|
|
296
|
+
return None
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def type_id_for_named_node(
|
|
300
|
+
node: Union[NameExpr, MemberExpr, SymbolNode],
|
|
301
|
+
) -> Optional[int]:
|
|
302
|
+
type_id, fullnames = _lookup.get(node.name, (None, None))
|
|
303
|
+
|
|
304
|
+
if type_id is None or fullnames is None:
|
|
305
|
+
return None
|
|
306
|
+
elif node.fullname in fullnames:
|
|
307
|
+
return type_id
|
|
308
|
+
else:
|
|
309
|
+
return None
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def type_id_for_fullname(fullname: str) -> Optional[int]:
|
|
313
|
+
tokens = fullname.split(".")
|
|
314
|
+
immediate = tokens[-1]
|
|
315
|
+
|
|
316
|
+
type_id, fullnames = _lookup.get(immediate, (None, None))
|
|
317
|
+
|
|
318
|
+
if type_id is None or fullnames is None:
|
|
319
|
+
return None
|
|
320
|
+
elif fullname in fullnames:
|
|
321
|
+
return type_id
|
|
322
|
+
else:
|
|
323
|
+
return None
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def expr_to_mapped_constructor(expr: Expression) -> CallExpr:
|
|
327
|
+
column_descriptor = NameExpr("__sa_Mapped")
|
|
328
|
+
column_descriptor.fullname = NAMED_TYPE_SQLA_MAPPED
|
|
329
|
+
member_expr = MemberExpr(column_descriptor, "_empty_constructor")
|
|
330
|
+
return CallExpr(
|
|
331
|
+
member_expr,
|
|
332
|
+
[expr],
|
|
333
|
+
[ARG_POS],
|
|
334
|
+
["arg1"],
|
|
335
|
+
)
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
# ext/mypy/plugin.py
|
|
2
|
+
# Copyright (C) 2021-2026 the SQLAlchemy authors and contributors
|
|
3
|
+
# <see AUTHORS file>
|
|
4
|
+
#
|
|
5
|
+
# This module is part of SQLAlchemy and is released under
|
|
6
|
+
# the MIT License: https://www.opensource.org/licenses/mit-license.php
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
Mypy plugin for SQLAlchemy ORM.
|
|
10
|
+
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from typing import Callable
|
|
15
|
+
from typing import List
|
|
16
|
+
from typing import Optional
|
|
17
|
+
from typing import Tuple
|
|
18
|
+
from typing import Type as TypingType
|
|
19
|
+
from typing import Union
|
|
20
|
+
|
|
21
|
+
from mypy import nodes
|
|
22
|
+
from mypy.mro import calculate_mro
|
|
23
|
+
from mypy.mro import MroError
|
|
24
|
+
from mypy.nodes import Block
|
|
25
|
+
from mypy.nodes import ClassDef
|
|
26
|
+
from mypy.nodes import GDEF
|
|
27
|
+
from mypy.nodes import MypyFile
|
|
28
|
+
from mypy.nodes import NameExpr
|
|
29
|
+
from mypy.nodes import SymbolTable
|
|
30
|
+
from mypy.nodes import SymbolTableNode
|
|
31
|
+
from mypy.nodes import TypeInfo
|
|
32
|
+
from mypy.plugin import AttributeContext
|
|
33
|
+
from mypy.plugin import ClassDefContext
|
|
34
|
+
from mypy.plugin import DynamicClassDefContext
|
|
35
|
+
from mypy.plugin import Plugin
|
|
36
|
+
from mypy.plugin import SemanticAnalyzerPluginInterface
|
|
37
|
+
from mypy.types import get_proper_type
|
|
38
|
+
from mypy.types import Instance
|
|
39
|
+
from mypy.types import Type
|
|
40
|
+
|
|
41
|
+
from . import decl_class
|
|
42
|
+
from . import names
|
|
43
|
+
from . import util
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
__import__("sqlalchemy-stubs")
|
|
47
|
+
except ImportError:
|
|
48
|
+
pass
|
|
49
|
+
else:
|
|
50
|
+
raise ImportError(
|
|
51
|
+
"The SQLAlchemy mypy plugin in SQLAlchemy "
|
|
52
|
+
"2.0 does not work with sqlalchemy-stubs or "
|
|
53
|
+
"sqlalchemy2-stubs installed, as well as with any other third party "
|
|
54
|
+
"SQLAlchemy stubs. Please uninstall all SQLAlchemy stubs "
|
|
55
|
+
"packages."
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class SQLAlchemyPlugin(Plugin):
|
|
60
|
+
def get_dynamic_class_hook(
|
|
61
|
+
self, fullname: str
|
|
62
|
+
) -> Optional[Callable[[DynamicClassDefContext], None]]:
|
|
63
|
+
if names.type_id_for_fullname(fullname) is names.DECLARATIVE_BASE:
|
|
64
|
+
return _dynamic_class_hook
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
def get_customize_class_mro_hook(
|
|
68
|
+
self, fullname: str
|
|
69
|
+
) -> Optional[Callable[[ClassDefContext], None]]:
|
|
70
|
+
return _fill_in_decorators
|
|
71
|
+
|
|
72
|
+
def get_class_decorator_hook(
|
|
73
|
+
self, fullname: str
|
|
74
|
+
) -> Optional[Callable[[ClassDefContext], None]]:
|
|
75
|
+
sym = self.lookup_fully_qualified(fullname)
|
|
76
|
+
|
|
77
|
+
if sym is not None and sym.node is not None:
|
|
78
|
+
type_id = names.type_id_for_named_node(sym.node)
|
|
79
|
+
if type_id is names.MAPPED_DECORATOR:
|
|
80
|
+
return _cls_decorator_hook
|
|
81
|
+
elif type_id in (
|
|
82
|
+
names.AS_DECLARATIVE,
|
|
83
|
+
names.AS_DECLARATIVE_BASE,
|
|
84
|
+
):
|
|
85
|
+
return _base_cls_decorator_hook
|
|
86
|
+
elif type_id is names.DECLARATIVE_MIXIN:
|
|
87
|
+
return _declarative_mixin_hook
|
|
88
|
+
|
|
89
|
+
return None
|
|
90
|
+
|
|
91
|
+
def get_metaclass_hook(
|
|
92
|
+
self, fullname: str
|
|
93
|
+
) -> Optional[Callable[[ClassDefContext], None]]:
|
|
94
|
+
if names.type_id_for_fullname(fullname) is names.DECLARATIVE_META:
|
|
95
|
+
# Set any classes that explicitly have metaclass=DeclarativeMeta
|
|
96
|
+
# as declarative so the check in `get_base_class_hook()` works
|
|
97
|
+
return _metaclass_cls_hook
|
|
98
|
+
|
|
99
|
+
return None
|
|
100
|
+
|
|
101
|
+
def get_base_class_hook(
|
|
102
|
+
self, fullname: str
|
|
103
|
+
) -> Optional[Callable[[ClassDefContext], None]]:
|
|
104
|
+
sym = self.lookup_fully_qualified(fullname)
|
|
105
|
+
|
|
106
|
+
if (
|
|
107
|
+
sym
|
|
108
|
+
and isinstance(sym.node, TypeInfo)
|
|
109
|
+
and util.has_declarative_base(sym.node)
|
|
110
|
+
):
|
|
111
|
+
return _base_cls_hook
|
|
112
|
+
|
|
113
|
+
return None
|
|
114
|
+
|
|
115
|
+
def get_attribute_hook(
|
|
116
|
+
self, fullname: str
|
|
117
|
+
) -> Optional[Callable[[AttributeContext], Type]]:
|
|
118
|
+
if fullname.startswith(
|
|
119
|
+
"sqlalchemy.orm.attributes.QueryableAttribute."
|
|
120
|
+
):
|
|
121
|
+
return _queryable_getattr_hook
|
|
122
|
+
|
|
123
|
+
return None
|
|
124
|
+
|
|
125
|
+
def get_additional_deps(
|
|
126
|
+
self, file: MypyFile
|
|
127
|
+
) -> List[Tuple[int, str, int]]:
|
|
128
|
+
return [
|
|
129
|
+
#
|
|
130
|
+
(10, "sqlalchemy.orm", -1),
|
|
131
|
+
(10, "sqlalchemy.orm.attributes", -1),
|
|
132
|
+
(10, "sqlalchemy.orm.decl_api", -1),
|
|
133
|
+
]
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def plugin(version: str) -> TypingType[SQLAlchemyPlugin]:
|
|
137
|
+
return SQLAlchemyPlugin
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _dynamic_class_hook(ctx: DynamicClassDefContext) -> None:
|
|
141
|
+
"""Generate a declarative Base class when the declarative_base() function
|
|
142
|
+
is encountered."""
|
|
143
|
+
|
|
144
|
+
_add_globals(ctx)
|
|
145
|
+
|
|
146
|
+
cls = ClassDef(ctx.name, Block([]))
|
|
147
|
+
cls.fullname = ctx.api.qualified_name(ctx.name)
|
|
148
|
+
|
|
149
|
+
info = TypeInfo(SymbolTable(), cls, ctx.api.cur_mod_id)
|
|
150
|
+
cls.info = info
|
|
151
|
+
_set_declarative_metaclass(ctx.api, cls)
|
|
152
|
+
|
|
153
|
+
cls_arg = util.get_callexpr_kwarg(ctx.call, "cls", expr_types=(NameExpr,))
|
|
154
|
+
if cls_arg is not None and isinstance(cls_arg.node, TypeInfo):
|
|
155
|
+
util.set_is_base(cls_arg.node)
|
|
156
|
+
decl_class.scan_declarative_assignments_and_apply_types(
|
|
157
|
+
cls_arg.node.defn, ctx.api, is_mixin_scan=True
|
|
158
|
+
)
|
|
159
|
+
info.bases = [Instance(cls_arg.node, [])]
|
|
160
|
+
else:
|
|
161
|
+
obj = ctx.api.named_type(names.NAMED_TYPE_BUILTINS_OBJECT)
|
|
162
|
+
|
|
163
|
+
info.bases = [obj]
|
|
164
|
+
|
|
165
|
+
try:
|
|
166
|
+
calculate_mro(info)
|
|
167
|
+
except MroError:
|
|
168
|
+
util.fail(
|
|
169
|
+
ctx.api, "Not able to calculate MRO for declarative base", ctx.call
|
|
170
|
+
)
|
|
171
|
+
obj = ctx.api.named_type(names.NAMED_TYPE_BUILTINS_OBJECT)
|
|
172
|
+
info.bases = [obj]
|
|
173
|
+
info.fallback_to_any = True
|
|
174
|
+
|
|
175
|
+
ctx.api.add_symbol_table_node(ctx.name, SymbolTableNode(GDEF, info))
|
|
176
|
+
util.set_is_base(info)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _fill_in_decorators(ctx: ClassDefContext) -> None:
|
|
180
|
+
for decorator in ctx.cls.decorators:
|
|
181
|
+
# set the ".fullname" attribute of a class decorator
|
|
182
|
+
# that is a MemberExpr. This causes the logic in
|
|
183
|
+
# semanal.py->apply_class_plugin_hooks to invoke the
|
|
184
|
+
# get_class_decorator_hook for our "registry.map_class()"
|
|
185
|
+
# and "registry.as_declarative_base()" methods.
|
|
186
|
+
# this seems like a bug in mypy that these decorators are otherwise
|
|
187
|
+
# skipped.
|
|
188
|
+
|
|
189
|
+
if (
|
|
190
|
+
isinstance(decorator, nodes.CallExpr)
|
|
191
|
+
and isinstance(decorator.callee, nodes.MemberExpr)
|
|
192
|
+
and decorator.callee.name == "as_declarative_base"
|
|
193
|
+
):
|
|
194
|
+
target = decorator.callee
|
|
195
|
+
elif (
|
|
196
|
+
isinstance(decorator, nodes.MemberExpr)
|
|
197
|
+
and decorator.name == "mapped"
|
|
198
|
+
):
|
|
199
|
+
target = decorator
|
|
200
|
+
else:
|
|
201
|
+
continue
|
|
202
|
+
|
|
203
|
+
if isinstance(target.expr, NameExpr):
|
|
204
|
+
sym = ctx.api.lookup_qualified(
|
|
205
|
+
target.expr.name, target, suppress_errors=True
|
|
206
|
+
)
|
|
207
|
+
else:
|
|
208
|
+
continue
|
|
209
|
+
|
|
210
|
+
if sym and sym.node:
|
|
211
|
+
sym_type = get_proper_type(sym.type)
|
|
212
|
+
if isinstance(sym_type, Instance):
|
|
213
|
+
target.fullname = f"{sym_type.type.fullname}.{target.name}"
|
|
214
|
+
else:
|
|
215
|
+
# if the registry is in the same file as where the
|
|
216
|
+
# decorator is used, it might not have semantic
|
|
217
|
+
# symbols applied and we can't get a fully qualified
|
|
218
|
+
# name or an inferred type, so we are actually going to
|
|
219
|
+
# flag an error in this case that they need to annotate
|
|
220
|
+
# it. The "registry" is declared just
|
|
221
|
+
# once (or few times), so they have to just not use
|
|
222
|
+
# type inference for its assignment in this one case.
|
|
223
|
+
util.fail(
|
|
224
|
+
ctx.api,
|
|
225
|
+
"Class decorator called %s(), but we can't "
|
|
226
|
+
"tell if it's from an ORM registry. Please "
|
|
227
|
+
"annotate the registry assignment, e.g. "
|
|
228
|
+
"my_registry: registry = registry()" % target.name,
|
|
229
|
+
sym.node,
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def _cls_decorator_hook(ctx: ClassDefContext) -> None:
|
|
234
|
+
_add_globals(ctx)
|
|
235
|
+
assert isinstance(ctx.reason, nodes.MemberExpr)
|
|
236
|
+
expr = ctx.reason.expr
|
|
237
|
+
|
|
238
|
+
assert isinstance(expr, nodes.RefExpr) and isinstance(expr.node, nodes.Var)
|
|
239
|
+
|
|
240
|
+
node_type = get_proper_type(expr.node.type)
|
|
241
|
+
|
|
242
|
+
assert (
|
|
243
|
+
isinstance(node_type, Instance)
|
|
244
|
+
and names.type_id_for_named_node(node_type.type) is names.REGISTRY
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
decl_class.scan_declarative_assignments_and_apply_types(ctx.cls, ctx.api)
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def _base_cls_decorator_hook(ctx: ClassDefContext) -> None:
|
|
251
|
+
_add_globals(ctx)
|
|
252
|
+
|
|
253
|
+
cls = ctx.cls
|
|
254
|
+
|
|
255
|
+
_set_declarative_metaclass(ctx.api, cls)
|
|
256
|
+
|
|
257
|
+
util.set_is_base(ctx.cls.info)
|
|
258
|
+
decl_class.scan_declarative_assignments_and_apply_types(
|
|
259
|
+
cls, ctx.api, is_mixin_scan=True
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def _declarative_mixin_hook(ctx: ClassDefContext) -> None:
|
|
264
|
+
_add_globals(ctx)
|
|
265
|
+
util.set_is_base(ctx.cls.info)
|
|
266
|
+
decl_class.scan_declarative_assignments_and_apply_types(
|
|
267
|
+
ctx.cls, ctx.api, is_mixin_scan=True
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def _metaclass_cls_hook(ctx: ClassDefContext) -> None:
|
|
272
|
+
util.set_is_base(ctx.cls.info)
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _base_cls_hook(ctx: ClassDefContext) -> None:
|
|
276
|
+
_add_globals(ctx)
|
|
277
|
+
decl_class.scan_declarative_assignments_and_apply_types(ctx.cls, ctx.api)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def _queryable_getattr_hook(ctx: AttributeContext) -> Type:
|
|
281
|
+
# how do I....tell it it has no attribute of a certain name?
|
|
282
|
+
# can't find any Type that seems to match that
|
|
283
|
+
return ctx.default_attr_type
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def _add_globals(ctx: Union[ClassDefContext, DynamicClassDefContext]) -> None:
|
|
287
|
+
"""Add __sa_DeclarativeMeta and __sa_Mapped symbol to the global space
|
|
288
|
+
for all class defs
|
|
289
|
+
|
|
290
|
+
"""
|
|
291
|
+
|
|
292
|
+
util.add_global(ctx, "sqlalchemy.orm", "Mapped", "__sa_Mapped")
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def _set_declarative_metaclass(
|
|
296
|
+
api: SemanticAnalyzerPluginInterface, target_cls: ClassDef
|
|
297
|
+
) -> None:
|
|
298
|
+
info = target_cls.info
|
|
299
|
+
sym = api.lookup_fully_qualified_or_none(
|
|
300
|
+
"sqlalchemy.orm.decl_api.DeclarativeMeta"
|
|
301
|
+
)
|
|
302
|
+
assert sym is not None and isinstance(sym.node, TypeInfo)
|
|
303
|
+
info.declared_metaclass = info.metaclass_type = Instance(sym.node, [])
|