SQLAlchemy 2.1.0b2__cp313-cp313t-win_arm64.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.
Files changed (270) hide show
  1. sqlalchemy/__init__.py +298 -0
  2. sqlalchemy/connectors/__init__.py +18 -0
  3. sqlalchemy/connectors/aioodbc.py +171 -0
  4. sqlalchemy/connectors/asyncio.py +476 -0
  5. sqlalchemy/connectors/pyodbc.py +250 -0
  6. sqlalchemy/dialects/__init__.py +62 -0
  7. sqlalchemy/dialects/_typing.py +30 -0
  8. sqlalchemy/dialects/mssql/__init__.py +89 -0
  9. sqlalchemy/dialects/mssql/aioodbc.py +63 -0
  10. sqlalchemy/dialects/mssql/base.py +4166 -0
  11. sqlalchemy/dialects/mssql/information_schema.py +285 -0
  12. sqlalchemy/dialects/mssql/json.py +140 -0
  13. sqlalchemy/dialects/mssql/mssqlpython.py +220 -0
  14. sqlalchemy/dialects/mssql/provision.py +196 -0
  15. sqlalchemy/dialects/mssql/pymssql.py +126 -0
  16. sqlalchemy/dialects/mssql/pyodbc.py +698 -0
  17. sqlalchemy/dialects/mysql/__init__.py +106 -0
  18. sqlalchemy/dialects/mysql/_mariadb_shim.py +312 -0
  19. sqlalchemy/dialects/mysql/aiomysql.py +226 -0
  20. sqlalchemy/dialects/mysql/asyncmy.py +214 -0
  21. sqlalchemy/dialects/mysql/base.py +3877 -0
  22. sqlalchemy/dialects/mysql/cymysql.py +106 -0
  23. sqlalchemy/dialects/mysql/dml.py +279 -0
  24. sqlalchemy/dialects/mysql/enumerated.py +277 -0
  25. sqlalchemy/dialects/mysql/expression.py +146 -0
  26. sqlalchemy/dialects/mysql/json.py +92 -0
  27. sqlalchemy/dialects/mysql/mariadb.py +67 -0
  28. sqlalchemy/dialects/mysql/mariadbconnector.py +330 -0
  29. sqlalchemy/dialects/mysql/mysqlconnector.py +296 -0
  30. sqlalchemy/dialects/mysql/mysqldb.py +312 -0
  31. sqlalchemy/dialects/mysql/provision.py +153 -0
  32. sqlalchemy/dialects/mysql/pymysql.py +157 -0
  33. sqlalchemy/dialects/mysql/pyodbc.py +156 -0
  34. sqlalchemy/dialects/mysql/reflection.py +724 -0
  35. sqlalchemy/dialects/mysql/reserved_words.py +570 -0
  36. sqlalchemy/dialects/mysql/types.py +845 -0
  37. sqlalchemy/dialects/oracle/__init__.py +85 -0
  38. sqlalchemy/dialects/oracle/base.py +3977 -0
  39. sqlalchemy/dialects/oracle/cx_oracle.py +1601 -0
  40. sqlalchemy/dialects/oracle/dictionary.py +507 -0
  41. sqlalchemy/dialects/oracle/json.py +158 -0
  42. sqlalchemy/dialects/oracle/oracledb.py +909 -0
  43. sqlalchemy/dialects/oracle/provision.py +288 -0
  44. sqlalchemy/dialects/oracle/types.py +367 -0
  45. sqlalchemy/dialects/oracle/vector.py +368 -0
  46. sqlalchemy/dialects/postgresql/__init__.py +171 -0
  47. sqlalchemy/dialects/postgresql/_psycopg_common.py +229 -0
  48. sqlalchemy/dialects/postgresql/array.py +534 -0
  49. sqlalchemy/dialects/postgresql/asyncpg.py +1323 -0
  50. sqlalchemy/dialects/postgresql/base.py +5789 -0
  51. sqlalchemy/dialects/postgresql/bitstring.py +327 -0
  52. sqlalchemy/dialects/postgresql/dml.py +360 -0
  53. sqlalchemy/dialects/postgresql/ext.py +593 -0
  54. sqlalchemy/dialects/postgresql/hstore.py +423 -0
  55. sqlalchemy/dialects/postgresql/json.py +408 -0
  56. sqlalchemy/dialects/postgresql/named_types.py +521 -0
  57. sqlalchemy/dialects/postgresql/operators.py +130 -0
  58. sqlalchemy/dialects/postgresql/pg8000.py +670 -0
  59. sqlalchemy/dialects/postgresql/pg_catalog.py +344 -0
  60. sqlalchemy/dialects/postgresql/provision.py +184 -0
  61. sqlalchemy/dialects/postgresql/psycopg.py +799 -0
  62. sqlalchemy/dialects/postgresql/psycopg2.py +860 -0
  63. sqlalchemy/dialects/postgresql/psycopg2cffi.py +61 -0
  64. sqlalchemy/dialects/postgresql/ranges.py +1002 -0
  65. sqlalchemy/dialects/postgresql/types.py +388 -0
  66. sqlalchemy/dialects/sqlite/__init__.py +57 -0
  67. sqlalchemy/dialects/sqlite/aiosqlite.py +321 -0
  68. sqlalchemy/dialects/sqlite/base.py +3063 -0
  69. sqlalchemy/dialects/sqlite/dml.py +279 -0
  70. sqlalchemy/dialects/sqlite/json.py +100 -0
  71. sqlalchemy/dialects/sqlite/provision.py +229 -0
  72. sqlalchemy/dialects/sqlite/pysqlcipher.py +161 -0
  73. sqlalchemy/dialects/sqlite/pysqlite.py +754 -0
  74. sqlalchemy/dialects/type_migration_guidelines.txt +145 -0
  75. sqlalchemy/engine/__init__.py +62 -0
  76. sqlalchemy/engine/_processors_cy.cp313t-win_arm64.pyd +0 -0
  77. sqlalchemy/engine/_processors_cy.py +92 -0
  78. sqlalchemy/engine/_result_cy.cp313t-win_arm64.pyd +0 -0
  79. sqlalchemy/engine/_result_cy.py +633 -0
  80. sqlalchemy/engine/_row_cy.cp313t-win_arm64.pyd +0 -0
  81. sqlalchemy/engine/_row_cy.py +232 -0
  82. sqlalchemy/engine/_util_cy.cp313t-win_arm64.pyd +0 -0
  83. sqlalchemy/engine/_util_cy.py +136 -0
  84. sqlalchemy/engine/base.py +3354 -0
  85. sqlalchemy/engine/characteristics.py +155 -0
  86. sqlalchemy/engine/create.py +877 -0
  87. sqlalchemy/engine/cursor.py +2421 -0
  88. sqlalchemy/engine/default.py +2402 -0
  89. sqlalchemy/engine/events.py +965 -0
  90. sqlalchemy/engine/interfaces.py +3495 -0
  91. sqlalchemy/engine/mock.py +134 -0
  92. sqlalchemy/engine/processors.py +82 -0
  93. sqlalchemy/engine/reflection.py +2100 -0
  94. sqlalchemy/engine/result.py +1966 -0
  95. sqlalchemy/engine/row.py +397 -0
  96. sqlalchemy/engine/strategies.py +16 -0
  97. sqlalchemy/engine/url.py +922 -0
  98. sqlalchemy/engine/util.py +156 -0
  99. sqlalchemy/event/__init__.py +26 -0
  100. sqlalchemy/event/api.py +220 -0
  101. sqlalchemy/event/attr.py +674 -0
  102. sqlalchemy/event/base.py +472 -0
  103. sqlalchemy/event/legacy.py +258 -0
  104. sqlalchemy/event/registry.py +390 -0
  105. sqlalchemy/events.py +17 -0
  106. sqlalchemy/exc.py +922 -0
  107. sqlalchemy/ext/__init__.py +11 -0
  108. sqlalchemy/ext/associationproxy.py +2072 -0
  109. sqlalchemy/ext/asyncio/__init__.py +29 -0
  110. sqlalchemy/ext/asyncio/base.py +281 -0
  111. sqlalchemy/ext/asyncio/engine.py +1487 -0
  112. sqlalchemy/ext/asyncio/exc.py +21 -0
  113. sqlalchemy/ext/asyncio/result.py +994 -0
  114. sqlalchemy/ext/asyncio/scoping.py +1679 -0
  115. sqlalchemy/ext/asyncio/session.py +2007 -0
  116. sqlalchemy/ext/automap.py +1701 -0
  117. sqlalchemy/ext/baked.py +559 -0
  118. sqlalchemy/ext/compiler.py +600 -0
  119. sqlalchemy/ext/declarative/__init__.py +65 -0
  120. sqlalchemy/ext/declarative/extensions.py +560 -0
  121. sqlalchemy/ext/horizontal_shard.py +481 -0
  122. sqlalchemy/ext/hybrid.py +1877 -0
  123. sqlalchemy/ext/indexable.py +364 -0
  124. sqlalchemy/ext/instrumentation.py +450 -0
  125. sqlalchemy/ext/mutable.py +1081 -0
  126. sqlalchemy/ext/orderinglist.py +439 -0
  127. sqlalchemy/ext/serializer.py +185 -0
  128. sqlalchemy/future/__init__.py +16 -0
  129. sqlalchemy/future/engine.py +15 -0
  130. sqlalchemy/inspection.py +174 -0
  131. sqlalchemy/log.py +283 -0
  132. sqlalchemy/orm/__init__.py +176 -0
  133. sqlalchemy/orm/_orm_constructors.py +2694 -0
  134. sqlalchemy/orm/_typing.py +179 -0
  135. sqlalchemy/orm/attributes.py +2868 -0
  136. sqlalchemy/orm/base.py +976 -0
  137. sqlalchemy/orm/bulk_persistence.py +2152 -0
  138. sqlalchemy/orm/clsregistry.py +582 -0
  139. sqlalchemy/orm/collections.py +1568 -0
  140. sqlalchemy/orm/context.py +3471 -0
  141. sqlalchemy/orm/decl_api.py +2280 -0
  142. sqlalchemy/orm/decl_base.py +2309 -0
  143. sqlalchemy/orm/dependency.py +1306 -0
  144. sqlalchemy/orm/descriptor_props.py +1183 -0
  145. sqlalchemy/orm/dynamic.py +307 -0
  146. sqlalchemy/orm/evaluator.py +379 -0
  147. sqlalchemy/orm/events.py +3386 -0
  148. sqlalchemy/orm/exc.py +237 -0
  149. sqlalchemy/orm/identity.py +302 -0
  150. sqlalchemy/orm/instrumentation.py +746 -0
  151. sqlalchemy/orm/interfaces.py +1589 -0
  152. sqlalchemy/orm/loading.py +1684 -0
  153. sqlalchemy/orm/mapped_collection.py +557 -0
  154. sqlalchemy/orm/mapper.py +4411 -0
  155. sqlalchemy/orm/path_registry.py +829 -0
  156. sqlalchemy/orm/persistence.py +1789 -0
  157. sqlalchemy/orm/properties.py +973 -0
  158. sqlalchemy/orm/query.py +3528 -0
  159. sqlalchemy/orm/relationships.py +3570 -0
  160. sqlalchemy/orm/scoping.py +2232 -0
  161. sqlalchemy/orm/session.py +5403 -0
  162. sqlalchemy/orm/state.py +1175 -0
  163. sqlalchemy/orm/state_changes.py +196 -0
  164. sqlalchemy/orm/strategies.py +3492 -0
  165. sqlalchemy/orm/strategy_options.py +2562 -0
  166. sqlalchemy/orm/sync.py +164 -0
  167. sqlalchemy/orm/unitofwork.py +798 -0
  168. sqlalchemy/orm/util.py +2438 -0
  169. sqlalchemy/orm/writeonly.py +694 -0
  170. sqlalchemy/pool/__init__.py +41 -0
  171. sqlalchemy/pool/base.py +1522 -0
  172. sqlalchemy/pool/events.py +375 -0
  173. sqlalchemy/pool/impl.py +582 -0
  174. sqlalchemy/py.typed +0 -0
  175. sqlalchemy/schema.py +74 -0
  176. sqlalchemy/sql/__init__.py +156 -0
  177. sqlalchemy/sql/_annotated_cols.py +397 -0
  178. sqlalchemy/sql/_dml_constructors.py +132 -0
  179. sqlalchemy/sql/_elements_constructors.py +2164 -0
  180. sqlalchemy/sql/_orm_types.py +20 -0
  181. sqlalchemy/sql/_selectable_constructors.py +840 -0
  182. sqlalchemy/sql/_typing.py +487 -0
  183. sqlalchemy/sql/_util_cy.cp313t-win_arm64.pyd +0 -0
  184. sqlalchemy/sql/_util_cy.py +127 -0
  185. sqlalchemy/sql/annotation.py +590 -0
  186. sqlalchemy/sql/base.py +2699 -0
  187. sqlalchemy/sql/cache_key.py +1066 -0
  188. sqlalchemy/sql/coercions.py +1373 -0
  189. sqlalchemy/sql/compiler.py +8327 -0
  190. sqlalchemy/sql/crud.py +1815 -0
  191. sqlalchemy/sql/ddl.py +1928 -0
  192. sqlalchemy/sql/default_comparator.py +654 -0
  193. sqlalchemy/sql/dml.py +1977 -0
  194. sqlalchemy/sql/elements.py +6033 -0
  195. sqlalchemy/sql/events.py +458 -0
  196. sqlalchemy/sql/expression.py +172 -0
  197. sqlalchemy/sql/functions.py +2305 -0
  198. sqlalchemy/sql/lambdas.py +1443 -0
  199. sqlalchemy/sql/naming.py +209 -0
  200. sqlalchemy/sql/operators.py +2897 -0
  201. sqlalchemy/sql/roles.py +332 -0
  202. sqlalchemy/sql/schema.py +6703 -0
  203. sqlalchemy/sql/selectable.py +7553 -0
  204. sqlalchemy/sql/sqltypes.py +4093 -0
  205. sqlalchemy/sql/traversals.py +1042 -0
  206. sqlalchemy/sql/type_api.py +2446 -0
  207. sqlalchemy/sql/util.py +1495 -0
  208. sqlalchemy/sql/visitors.py +1157 -0
  209. sqlalchemy/testing/__init__.py +96 -0
  210. sqlalchemy/testing/assertions.py +1007 -0
  211. sqlalchemy/testing/assertsql.py +519 -0
  212. sqlalchemy/testing/asyncio.py +128 -0
  213. sqlalchemy/testing/config.py +440 -0
  214. sqlalchemy/testing/engines.py +483 -0
  215. sqlalchemy/testing/entities.py +117 -0
  216. sqlalchemy/testing/exclusions.py +476 -0
  217. sqlalchemy/testing/fixtures/__init__.py +30 -0
  218. sqlalchemy/testing/fixtures/base.py +384 -0
  219. sqlalchemy/testing/fixtures/mypy.py +247 -0
  220. sqlalchemy/testing/fixtures/orm.py +227 -0
  221. sqlalchemy/testing/fixtures/sql.py +538 -0
  222. sqlalchemy/testing/pickleable.py +155 -0
  223. sqlalchemy/testing/plugin/__init__.py +6 -0
  224. sqlalchemy/testing/plugin/bootstrap.py +51 -0
  225. sqlalchemy/testing/plugin/plugin_base.py +828 -0
  226. sqlalchemy/testing/plugin/pytestplugin.py +892 -0
  227. sqlalchemy/testing/profiling.py +329 -0
  228. sqlalchemy/testing/provision.py +613 -0
  229. sqlalchemy/testing/requirements.py +1978 -0
  230. sqlalchemy/testing/schema.py +198 -0
  231. sqlalchemy/testing/suite/__init__.py +19 -0
  232. sqlalchemy/testing/suite/test_cte.py +237 -0
  233. sqlalchemy/testing/suite/test_ddl.py +420 -0
  234. sqlalchemy/testing/suite/test_dialect.py +776 -0
  235. sqlalchemy/testing/suite/test_insert.py +630 -0
  236. sqlalchemy/testing/suite/test_reflection.py +3557 -0
  237. sqlalchemy/testing/suite/test_results.py +660 -0
  238. sqlalchemy/testing/suite/test_rowcount.py +258 -0
  239. sqlalchemy/testing/suite/test_select.py +2112 -0
  240. sqlalchemy/testing/suite/test_sequence.py +317 -0
  241. sqlalchemy/testing/suite/test_table_via_select.py +686 -0
  242. sqlalchemy/testing/suite/test_types.py +2271 -0
  243. sqlalchemy/testing/suite/test_unicode_ddl.py +189 -0
  244. sqlalchemy/testing/suite/test_update_delete.py +139 -0
  245. sqlalchemy/testing/util.py +535 -0
  246. sqlalchemy/testing/warnings.py +52 -0
  247. sqlalchemy/types.py +76 -0
  248. sqlalchemy/util/__init__.py +158 -0
  249. sqlalchemy/util/_collections.py +688 -0
  250. sqlalchemy/util/_collections_cy.cp313t-win_arm64.pyd +0 -0
  251. sqlalchemy/util/_collections_cy.pxd +8 -0
  252. sqlalchemy/util/_collections_cy.py +516 -0
  253. sqlalchemy/util/_has_cython.py +46 -0
  254. sqlalchemy/util/_immutabledict_cy.cp313t-win_arm64.pyd +0 -0
  255. sqlalchemy/util/_immutabledict_cy.py +240 -0
  256. sqlalchemy/util/compat.py +299 -0
  257. sqlalchemy/util/concurrency.py +322 -0
  258. sqlalchemy/util/cython.py +79 -0
  259. sqlalchemy/util/deprecations.py +401 -0
  260. sqlalchemy/util/langhelpers.py +2320 -0
  261. sqlalchemy/util/preloaded.py +152 -0
  262. sqlalchemy/util/queue.py +304 -0
  263. sqlalchemy/util/tool_support.py +201 -0
  264. sqlalchemy/util/topological.py +120 -0
  265. sqlalchemy/util/typing.py +711 -0
  266. sqlalchemy-2.1.0b2.dist-info/METADATA +269 -0
  267. sqlalchemy-2.1.0b2.dist-info/RECORD +270 -0
  268. sqlalchemy-2.1.0b2.dist-info/WHEEL +5 -0
  269. sqlalchemy-2.1.0b2.dist-info/licenses/LICENSE +19 -0
  270. sqlalchemy-2.1.0b2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,487 @@
1
+ # sql/_typing.py
2
+ # Copyright (C) 2022-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
+ import operator
11
+ from typing import Any
12
+ from typing import Callable
13
+ from typing import Dict
14
+ from typing import Generic
15
+ from typing import Iterable
16
+ from typing import Literal
17
+ from typing import Mapping
18
+ from typing import NoReturn
19
+ from typing import Optional
20
+ from typing import overload
21
+ from typing import Protocol
22
+ from typing import Set
23
+ from typing import Type
24
+ from typing import TYPE_CHECKING
25
+ from typing import TypeAlias
26
+ from typing import TypeVar
27
+ from typing import Union
28
+
29
+ from . import roles
30
+ from .. import exc
31
+ from .. import util
32
+ from ..inspection import Inspectable
33
+ from ..util.typing import TupleAny
34
+ from ..util.typing import TypeVarTuple
35
+ from ..util.typing import Unpack
36
+
37
+ if TYPE_CHECKING:
38
+ from datetime import date
39
+ from datetime import datetime
40
+ from datetime import time
41
+ from datetime import timedelta
42
+ from decimal import Decimal
43
+ from typing import TypeGuard
44
+ from uuid import UUID
45
+
46
+ from .base import Executable
47
+ from .compiler import Compiled
48
+ from .compiler import DDLCompiler
49
+ from .compiler import SQLCompiler
50
+ from .dml import UpdateBase
51
+ from .dml import ValuesBase
52
+ from .elements import ClauseElement
53
+ from .elements import ColumnElement
54
+ from .elements import KeyedColumnElement
55
+ from .elements import quoted_name
56
+ from .elements import SQLCoreOperations
57
+ from .elements import TextClause
58
+ from .lambdas import LambdaElement
59
+ from .roles import FromClauseRole
60
+ from .schema import Column
61
+ from .selectable import Alias
62
+ from .selectable import CompoundSelect
63
+ from .selectable import CTE
64
+ from .selectable import FromClause
65
+ from .selectable import Join
66
+ from .selectable import NamedFromClause
67
+ from .selectable import ReturnsRows
68
+ from .selectable import Select
69
+ from .selectable import Selectable
70
+ from .selectable import SelectBase
71
+ from .selectable import Subquery
72
+ from .selectable import TableClause
73
+ from .sqltypes import TableValueType
74
+ from .sqltypes import TupleType
75
+ from .type_api import TypeEngine
76
+ from ..engine import Connection
77
+ from ..engine import Dialect
78
+ from ..engine import Engine
79
+ from ..engine.mock import MockConnection
80
+
81
+ _T = TypeVar("_T", bound=Any)
82
+ _T_co = TypeVar("_T_co", bound=Any, covariant=True)
83
+ _Ts = TypeVarTuple("_Ts")
84
+ _Ts2 = TypeVarTuple("_Ts2")
85
+
86
+
87
+ _CE = TypeVar("_CE", bound="ColumnElement[Any]")
88
+
89
+ _CLE = TypeVar("_CLE", bound="ClauseElement")
90
+
91
+
92
+ class _HasClauseElement(Protocol, Generic[_T_co]):
93
+ """indicates a class that has a __clause_element__() method"""
94
+
95
+ def __clause_element__(self) -> roles.ExpressionElementRole[_T_co]: ...
96
+
97
+
98
+ class _CoreAdapterProto(Protocol):
99
+ """protocol for the ClauseAdapter/ColumnAdapter.traverse() method."""
100
+
101
+ def __call__(self, obj: _CE) -> _CE: ...
102
+
103
+
104
+ class _HasDialect(Protocol):
105
+ """protocol for Engine/Connection-like objects that have dialect
106
+ attribute.
107
+ """
108
+
109
+ @property
110
+ def dialect(self) -> Dialect: ...
111
+
112
+
113
+ # match column types that are not ORM entities
114
+ _NOT_ENTITY = TypeVar(
115
+ "_NOT_ENTITY",
116
+ int,
117
+ str,
118
+ bool,
119
+ "datetime",
120
+ "date",
121
+ "time",
122
+ "timedelta",
123
+ "UUID",
124
+ float,
125
+ "Decimal",
126
+ )
127
+
128
+ _StarOrOne = Literal["*", 1]
129
+
130
+ _MAYBE_ENTITY = TypeVar(
131
+ "_MAYBE_ENTITY",
132
+ roles.ColumnsClauseRole,
133
+ _StarOrOne,
134
+ Type[Any],
135
+ Inspectable[_HasClauseElement[Any]],
136
+ _HasClauseElement[Any],
137
+ )
138
+
139
+
140
+ # convention:
141
+ # XYZArgument - something that the end user is passing to a public API method
142
+ # XYZElement - the internal representation that we use for the thing.
143
+ # the coercions system is responsible for converting from XYZArgument to
144
+ # XYZElement.
145
+
146
+ _TextCoercedExpressionArgument = Union[
147
+ str,
148
+ "TextClause",
149
+ "ColumnElement[_T]",
150
+ _HasClauseElement[_T],
151
+ roles.ExpressionElementRole[_T],
152
+ ]
153
+
154
+ _ColumnsClauseArgument = Union[
155
+ roles.TypedColumnsClauseRole[_T],
156
+ roles.ColumnsClauseRole,
157
+ "SQLCoreOperations[_T]",
158
+ _StarOrOne,
159
+ Type[_T],
160
+ Inspectable[_HasClauseElement[_T]],
161
+ _HasClauseElement[_T],
162
+ ]
163
+ """open-ended SELECT columns clause argument.
164
+
165
+ Includes column expressions, tables, ORM mapped entities, a few literal values.
166
+
167
+ This type is used for lists of columns / entities to be returned in result
168
+ sets; select(...), insert().returning(...), etc.
169
+
170
+
171
+ """
172
+
173
+ _TypedColumnClauseArgument = Union[
174
+ roles.TypedColumnsClauseRole[_T],
175
+ "SQLCoreOperations[_T]",
176
+ Type[_T],
177
+ ]
178
+
179
+ _T0 = TypeVar("_T0", bound=Any)
180
+ _T1 = TypeVar("_T1", bound=Any)
181
+ _T2 = TypeVar("_T2", bound=Any)
182
+ _T3 = TypeVar("_T3", bound=Any)
183
+ _T4 = TypeVar("_T4", bound=Any)
184
+ _T5 = TypeVar("_T5", bound=Any)
185
+ _T6 = TypeVar("_T6", bound=Any)
186
+ _T7 = TypeVar("_T7", bound=Any)
187
+ _T8 = TypeVar("_T8", bound=Any)
188
+ _T9 = TypeVar("_T9", bound=Any)
189
+
190
+
191
+ _OnlyColumnArgument = Union[
192
+ "ColumnElement[_T]",
193
+ _HasClauseElement[_T],
194
+ roles.DMLColumnRole,
195
+ ]
196
+ """A narrow type that is looking for a ColumnClause (e.g. table column with a
197
+ name) or an ORM element that produces this.
198
+
199
+ This is used for constructs that need a named column to represent a
200
+ position in a selectable, like TextClause().columns() or values(...).
201
+
202
+ """
203
+
204
+ _ColumnExpressionArgument = Union[
205
+ "ColumnElement[_T]",
206
+ _HasClauseElement[_T],
207
+ "SQLCoreOperations[_T]",
208
+ roles.ExpressionElementRole[_T],
209
+ roles.TypedColumnsClauseRole[_T],
210
+ Callable[[], "ColumnElement[_T]"],
211
+ "LambdaElement",
212
+ ]
213
+ "See docs in public alias ColumnExpressionArgument."
214
+
215
+ ColumnExpressionArgument: TypeAlias = _ColumnExpressionArgument[_T]
216
+ """Narrower "column expression" argument.
217
+
218
+ This type is used for all the other "column" kinds of expressions that
219
+ typically represent a single SQL column expression, not a set of columns the
220
+ way a table or ORM entity does.
221
+
222
+ This includes ColumnElement, or ORM-mapped attributes that will have a
223
+ ``__clause_element__()`` method, it also has the ExpressionElementRole
224
+ overall which brings in the TextClause object also.
225
+
226
+ .. versionadded:: 2.0.13
227
+
228
+ """
229
+
230
+ _ColumnExpressionOrLiteralArgument = Union[Any, _ColumnExpressionArgument[_T]]
231
+
232
+ _ColumnExpressionOrStrLabelArgument = Union[str, _ColumnExpressionArgument[_T]]
233
+
234
+ _ByArgument = Union[
235
+ Iterable[_ColumnExpressionOrStrLabelArgument[Any]],
236
+ _ColumnExpressionOrStrLabelArgument[Any],
237
+ ]
238
+ """Used for keyword-based ``order_by`` and ``partition_by`` parameters."""
239
+
240
+
241
+ _InfoType = Dict[Any, Any]
242
+ """the .info dictionary accepted and used throughout Core /ORM"""
243
+
244
+ _FromClauseArgument = Union[
245
+ roles.FromClauseRole,
246
+ roles.TypedColumnsClauseRole[Any],
247
+ Type[Any],
248
+ Inspectable[_HasClauseElement[Any]],
249
+ _HasClauseElement[Any],
250
+ ]
251
+ """A FROM clause, like we would send to select().select_from().
252
+
253
+ Also accommodates ORM entities and related constructs.
254
+
255
+ """
256
+
257
+ _JoinTargetArgument = Union[_FromClauseArgument, roles.JoinTargetRole]
258
+ """target for join() builds on _FromClauseArgument to include additional
259
+ join target roles such as those which come from the ORM.
260
+
261
+ """
262
+
263
+ _OnClauseArgument = Union[_ColumnExpressionArgument[Any], roles.OnClauseRole]
264
+ """target for an ON clause, includes additional roles such as those which
265
+ come from the ORM.
266
+
267
+ """
268
+
269
+ _SelectStatementForCompoundArgument = Union[
270
+ "Select[Unpack[_Ts]]",
271
+ "CompoundSelect[Unpack[_Ts]]",
272
+ roles.CompoundElementRole,
273
+ ]
274
+ """SELECT statement acceptable by ``union()`` and other SQL set operations"""
275
+
276
+ _DMLColumnArgument = Union[
277
+ str,
278
+ _HasClauseElement[Any],
279
+ roles.DMLColumnRole,
280
+ "SQLCoreOperations[Any]",
281
+ ]
282
+ """A DML column expression. This is a "key" inside of insert().values(),
283
+ update().values(), and related.
284
+
285
+ These are usually strings or SQL table columns.
286
+
287
+ There's also edge cases like JSON expression assignment, which we would want
288
+ the DMLColumnRole to be able to accommodate.
289
+
290
+ """
291
+
292
+
293
+ _DMLKey = TypeVar("_DMLKey", bound=_DMLColumnArgument)
294
+ _DMLColumnKeyMapping = Mapping[_DMLKey, Any]
295
+
296
+
297
+ _DDLColumnArgument = Union[str, "Column[Any]", roles.DDLConstraintColumnRole]
298
+ """DDL column.
299
+
300
+ used for :class:`.PrimaryKeyConstraint`, :class:`.UniqueConstraint`, etc.
301
+
302
+ """
303
+
304
+ _DDLColumnReferenceArgument = _DDLColumnArgument
305
+
306
+ _DMLTableArgument = Union[
307
+ "TableClause",
308
+ "Join",
309
+ "Alias",
310
+ "CTE",
311
+ Type[Any],
312
+ Inspectable[_HasClauseElement[Any]],
313
+ _HasClauseElement[Any],
314
+ ]
315
+
316
+ _PropagateAttrsType = util.immutabledict[str, Any]
317
+
318
+ _TypeEngineArgument = Union[Type["TypeEngine[_T]"], "TypeEngine[_T]"]
319
+
320
+ _EquivalentColumnMap = Dict["ColumnElement[Any]", Set["ColumnElement[Any]"]]
321
+
322
+ _LimitOffsetType = Union[int, _ColumnExpressionArgument[int], None]
323
+
324
+ _AutoIncrementType = Union[bool, Literal["auto", "ignore_fk"]]
325
+
326
+ _CreateDropBind = Union["Engine", "Connection", "MockConnection"]
327
+
328
+ if TYPE_CHECKING:
329
+
330
+ def is_sql_compiler(c: Compiled) -> TypeGuard[SQLCompiler]: ...
331
+
332
+ def is_ddl_compiler(c: Compiled) -> TypeGuard[DDLCompiler]: ...
333
+
334
+ def is_named_from_clause(
335
+ t: FromClauseRole,
336
+ ) -> TypeGuard[NamedFromClause]: ...
337
+
338
+ def is_column_element(
339
+ c: ClauseElement,
340
+ ) -> TypeGuard[ColumnElement[Any]]: ...
341
+
342
+ def is_keyed_column_element(
343
+ c: ClauseElement,
344
+ ) -> TypeGuard[KeyedColumnElement[Any]]: ...
345
+
346
+ def is_text_clause(c: ClauseElement) -> TypeGuard[TextClause]: ...
347
+
348
+ def is_from_clause(c: ClauseElement) -> TypeGuard[FromClause]: ...
349
+
350
+ def is_tuple_type(t: TypeEngine[Any]) -> TypeGuard[TupleType]: ...
351
+
352
+ def is_table_value_type(
353
+ t: TypeEngine[Any],
354
+ ) -> TypeGuard[TableValueType]: ...
355
+
356
+ def is_selectable(t: Any) -> TypeGuard[Selectable]: ...
357
+
358
+ def is_select_base(
359
+ t: Union[Executable, ReturnsRows],
360
+ ) -> TypeGuard[SelectBase]: ...
361
+
362
+ def is_select_statement(
363
+ t: Union[Executable, ReturnsRows],
364
+ ) -> TypeGuard[Select[Unpack[TupleAny]]]: ...
365
+
366
+ def is_table(t: FromClause) -> TypeGuard[TableClause]: ...
367
+
368
+ def is_subquery(t: FromClause) -> TypeGuard[Subquery]: ...
369
+
370
+ def is_dml(c: ClauseElement) -> TypeGuard[UpdateBase]: ...
371
+
372
+ else:
373
+ is_sql_compiler = operator.attrgetter("is_sql")
374
+ is_ddl_compiler = operator.attrgetter("is_ddl")
375
+ is_named_from_clause = operator.attrgetter("named_with_column")
376
+ is_column_element = operator.attrgetter("_is_column_element")
377
+ is_keyed_column_element = operator.attrgetter("_is_keyed_column_element")
378
+ is_text_clause = operator.attrgetter("_is_text_clause")
379
+ is_from_clause = operator.attrgetter("_is_from_clause")
380
+ is_tuple_type = operator.attrgetter("_is_tuple_type")
381
+ is_table_value_type = operator.attrgetter("_is_table_value")
382
+ is_selectable = operator.attrgetter("is_selectable")
383
+ is_select_base = operator.attrgetter("_is_select_base")
384
+ is_select_statement = operator.attrgetter("_is_select_statement")
385
+ is_table = operator.attrgetter("_is_table")
386
+ is_subquery = operator.attrgetter("_is_subquery")
387
+ is_dml = operator.attrgetter("is_dml")
388
+
389
+
390
+ def has_schema_attr(t: FromClauseRole) -> TypeGuard[TableClause]:
391
+ return hasattr(t, "schema")
392
+
393
+
394
+ def is_quoted_name(s: str) -> TypeGuard[quoted_name]:
395
+ return hasattr(s, "quote")
396
+
397
+
398
+ def is_has_clause_element(s: object) -> TypeGuard[_HasClauseElement[Any]]:
399
+ return hasattr(s, "__clause_element__")
400
+
401
+
402
+ def is_insert_update(c: ClauseElement) -> TypeGuard[ValuesBase]:
403
+ return c.is_dml and (c.is_insert or c.is_update) # type: ignore
404
+
405
+
406
+ def _no_kw() -> exc.ArgumentError:
407
+ return exc.ArgumentError(
408
+ "Additional keyword arguments are not accepted by this "
409
+ "function/method. The presence of **kw is for pep-484 typing purposes"
410
+ )
411
+
412
+
413
+ def _unexpected_kw(methname: str, kw: Dict[str, Any]) -> NoReturn:
414
+ k = list(kw)[0]
415
+ raise TypeError(f"{methname} got an unexpected keyword argument '{k}'")
416
+
417
+
418
+ @overload
419
+ def Nullable(
420
+ val: "SQLCoreOperations[_T]",
421
+ ) -> "SQLCoreOperations[Optional[_T]]": ...
422
+
423
+
424
+ @overload
425
+ def Nullable(
426
+ val: roles.ExpressionElementRole[_T],
427
+ ) -> roles.ExpressionElementRole[Optional[_T]]: ...
428
+
429
+
430
+ @overload
431
+ def Nullable(val: Type[_T]) -> Type[Optional[_T]]: ...
432
+
433
+
434
+ def Nullable(
435
+ val: _TypedColumnClauseArgument[_T],
436
+ ) -> _TypedColumnClauseArgument[Optional[_T]]:
437
+ """Types a column or ORM class as nullable.
438
+
439
+ This can be used in select and other contexts to express that the value of
440
+ a column can be null, for example due to an outer join::
441
+
442
+ stmt1 = select(A, Nullable(B)).outerjoin(A.bs)
443
+ stmt2 = select(A.data, Nullable(B.data)).outerjoin(A.bs)
444
+
445
+ At runtime this method returns the input unchanged.
446
+
447
+ .. versionadded:: 2.0.20
448
+ """
449
+ return val
450
+
451
+
452
+ @overload
453
+ def NotNullable(
454
+ val: "SQLCoreOperations[Optional[_T]]",
455
+ ) -> "SQLCoreOperations[_T]": ...
456
+
457
+
458
+ @overload
459
+ def NotNullable(
460
+ val: roles.ExpressionElementRole[Optional[_T]],
461
+ ) -> roles.ExpressionElementRole[_T]: ...
462
+
463
+
464
+ @overload
465
+ def NotNullable(val: Type[Optional[_T]]) -> Type[_T]: ...
466
+
467
+
468
+ @overload
469
+ def NotNullable(val: Optional[Type[_T]]) -> Type[_T]: ...
470
+
471
+
472
+ def NotNullable(
473
+ val: Union[_TypedColumnClauseArgument[Optional[_T]], Optional[Type[_T]]],
474
+ ) -> _TypedColumnClauseArgument[_T]:
475
+ """Types a column or ORM class as not nullable.
476
+
477
+ This can be used in select and other contexts to express that the value of
478
+ a column cannot be null, for example due to a where condition on a
479
+ nullable column::
480
+
481
+ stmt = select(NotNullable(A.value)).where(A.value.is_not(None))
482
+
483
+ At runtime this method returns the input unchanged.
484
+
485
+ .. versionadded:: 2.0.20
486
+ """
487
+ return val # type: ignore
@@ -0,0 +1,127 @@
1
+ # sql/_util_cy.py
2
+ # Copyright (C) 2010-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
+ # mypy: disable-error-code="untyped-decorator"
8
+
9
+ from __future__ import annotations
10
+
11
+ from typing import Dict
12
+ from typing import Literal
13
+ from typing import Tuple
14
+ from typing import TYPE_CHECKING
15
+ from typing import Union
16
+
17
+ if TYPE_CHECKING:
18
+ from .cache_key import CacheConst
19
+ from ..engine.interfaces import _CoreSingleExecuteParams
20
+
21
+ # START GENERATED CYTHON IMPORT
22
+ # This section is automatically generated by the script tools/cython_imports.py
23
+ try:
24
+ # NOTE: the cython compiler needs this "import cython" in the file, it
25
+ # can't be only "from sqlalchemy.util import cython" with the fallback
26
+ # in that module
27
+ import cython
28
+ except ModuleNotFoundError:
29
+ from sqlalchemy.util import cython
30
+
31
+
32
+ def _is_compiled() -> bool:
33
+ """Utility function to indicate if this module is compiled or not."""
34
+ return cython.compiled # type: ignore[no-any-return,unused-ignore]
35
+
36
+
37
+ # END GENERATED CYTHON IMPORT
38
+
39
+ if cython.compiled:
40
+ from cython.cimports.sqlalchemy.util._collections_cy import _get_id
41
+ else:
42
+ _get_id = id
43
+
44
+
45
+ @cython.cclass
46
+ class prefix_anon_map(Dict[str, str]):
47
+ """A map that creates new keys for missing key access.
48
+
49
+ Considers keys of the form "<ident> <name>" to produce
50
+ new symbols "<name>_<index>", where "index" is an incrementing integer
51
+ corresponding to <name>.
52
+
53
+ Inlines the approach taken by :class:`sqlalchemy.util.PopulateDict` which
54
+ is otherwise usually used for this type of operation.
55
+
56
+ """
57
+
58
+ def __missing__(self, key: str, /) -> str:
59
+ derived: str
60
+ value: str
61
+ self_dict: dict = self # type: ignore[type-arg]
62
+
63
+ derived = key.split(" ", 1)[1]
64
+
65
+ anonymous_counter: int = self_dict.get(derived, 1)
66
+ self_dict[derived] = anonymous_counter + 1
67
+ value = f"{derived}_{anonymous_counter}"
68
+ self_dict[key] = value
69
+ return value
70
+
71
+
72
+ _AM_KEY = Union[int, str, "CacheConst"]
73
+ _AM_VALUE = Union[int, Literal[True], "_CoreSingleExecuteParams"]
74
+
75
+
76
+ @cython.cclass
77
+ class anon_map(Dict[_AM_KEY, _AM_VALUE]):
78
+ """A map that creates new keys for missing key access.
79
+
80
+ Produces an incrementing sequence given a series of unique keys.
81
+
82
+ This is similar to the compiler prefix_anon_map class although simpler.
83
+
84
+ Inlines the approach taken by :class:`sqlalchemy.util.PopulateDict` which
85
+ is otherwise usually used for this type of operation.
86
+
87
+ """
88
+
89
+ if cython.compiled:
90
+ _index: cython.uint
91
+
92
+ def __cinit__(self): # type: ignore[no-untyped-def]
93
+ self._index = 0
94
+
95
+ else:
96
+ _index: int = 0 # type: ignore[no-redef]
97
+
98
+ @cython.cfunc
99
+ @cython.inline
100
+ def _add_missing(self: anon_map, key: _AM_KEY, /) -> int:
101
+ val: int = self._index
102
+ self._index += 1
103
+ self_dict: dict = self # type: ignore[type-arg]
104
+ self_dict[key] = val
105
+ return val
106
+
107
+ def get_anon(self: anon_map, obj: object, /) -> Tuple[int, bool]:
108
+ self_dict: dict = self # type: ignore[type-arg]
109
+
110
+ idself: int = _get_id(obj)
111
+ if idself in self_dict:
112
+ return self_dict[idself], True
113
+ else:
114
+ return self._add_missing(idself), False
115
+
116
+ if cython.compiled:
117
+
118
+ def __getitem__(self: anon_map, key: _AM_KEY, /) -> _AM_VALUE:
119
+ self_dict: dict = self # type: ignore[type-arg]
120
+
121
+ if key in self_dict:
122
+ return self_dict[key] # type:ignore[no-any-return]
123
+ else:
124
+ return self._add_missing(key) # type:ignore[no-any-return]
125
+
126
+ def __missing__(self: anon_map, key: _AM_KEY, /) -> int:
127
+ return self._add_missing(key) # type:ignore[no-any-return]