SQLAlchemy 2.1.0rc1__cp315-cp315-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.
Files changed (276) hide show
  1. sqlalchemy/__init__.py +299 -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 +248 -0
  6. sqlalchemy/dialects/__init__.py +62 -0
  7. sqlalchemy/dialects/_typing.py +29 -0
  8. sqlalchemy/dialects/mssql/__init__.py +88 -0
  9. sqlalchemy/dialects/mssql/aioodbc.py +63 -0
  10. sqlalchemy/dialects/mssql/base.py +4833 -0
  11. sqlalchemy/dialects/mssql/information_schema.py +345 -0
  12. sqlalchemy/dialects/mssql/json.py +140 -0
  13. sqlalchemy/dialects/mssql/mssqlpython.py +242 -0
  14. sqlalchemy/dialects/mssql/provision.py +196 -0
  15. sqlalchemy/dialects/mssql/pymssql.py +130 -0
  16. sqlalchemy/dialects/mssql/pyodbc.py +697 -0
  17. sqlalchemy/dialects/mysql/__init__.py +106 -0
  18. sqlalchemy/dialects/mysql/_mariadb_shim.py +312 -0
  19. sqlalchemy/dialects/mysql/aiomysql.py +260 -0
  20. sqlalchemy/dialects/mysql/asyncmy.py +241 -0
  21. sqlalchemy/dialects/mysql/base.py +3896 -0
  22. sqlalchemy/dialects/mysql/cymysql.py +107 -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 +314 -0
  29. sqlalchemy/dialects/mysql/mysqlconnector.py +291 -0
  30. sqlalchemy/dialects/mysql/mysqldb.py +318 -0
  31. sqlalchemy/dialects/mysql/provision.py +153 -0
  32. sqlalchemy/dialects/mysql/pymysql.py +188 -0
  33. sqlalchemy/dialects/mysql/pyodbc.py +157 -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 +3847 -0
  39. sqlalchemy/dialects/oracle/cx_oracle.py +1736 -0
  40. sqlalchemy/dialects/oracle/dictionary.py +507 -0
  41. sqlalchemy/dialects/oracle/json.py +157 -0
  42. sqlalchemy/dialects/oracle/oracledb.py +898 -0
  43. sqlalchemy/dialects/oracle/provision.py +288 -0
  44. sqlalchemy/dialects/oracle/types.py +367 -0
  45. sqlalchemy/dialects/oracle/vector.py +366 -0
  46. sqlalchemy/dialects/postgresql/__init__.py +170 -0
  47. sqlalchemy/dialects/postgresql/_psycopg_common.py +232 -0
  48. sqlalchemy/dialects/postgresql/array.py +534 -0
  49. sqlalchemy/dialects/postgresql/asyncpg.py +1318 -0
  50. sqlalchemy/dialects/postgresql/base.py +5935 -0
  51. sqlalchemy/dialects/postgresql/bitstring.py +327 -0
  52. sqlalchemy/dialects/postgresql/dml.py +360 -0
  53. sqlalchemy/dialects/postgresql/ext.py +599 -0
  54. sqlalchemy/dialects/postgresql/hstore.py +422 -0
  55. sqlalchemy/dialects/postgresql/json.py +411 -0
  56. sqlalchemy/dialects/postgresql/named_types.py +535 -0
  57. sqlalchemy/dialects/postgresql/operators.py +129 -0
  58. sqlalchemy/dialects/postgresql/pg8000.py +655 -0
  59. sqlalchemy/dialects/postgresql/pg_catalog.py +345 -0
  60. sqlalchemy/dialects/postgresql/provision.py +202 -0
  61. sqlalchemy/dialects/postgresql/psycopg.py +800 -0
  62. sqlalchemy/dialects/postgresql/psycopg2.py +860 -0
  63. sqlalchemy/dialects/postgresql/psycopg2cffi.py +62 -0
  64. sqlalchemy/dialects/postgresql/ranges.py +1002 -0
  65. sqlalchemy/dialects/postgresql/types.py +388 -0
  66. sqlalchemy/dialects/sqlite/__init__.py +59 -0
  67. sqlalchemy/dialects/sqlite/aiosqlite.py +375 -0
  68. sqlalchemy/dialects/sqlite/base.py +3103 -0
  69. sqlalchemy/dialects/sqlite/dml.py +314 -0
  70. sqlalchemy/dialects/sqlite/json.py +134 -0
  71. sqlalchemy/dialects/sqlite/provision.py +237 -0
  72. sqlalchemy/dialects/sqlite/pysqlcipher.py +166 -0
  73. sqlalchemy/dialects/sqlite/pysqlite.py +959 -0
  74. sqlalchemy/dialects/type_migration_guidelines.txt +145 -0
  75. sqlalchemy/engine/__init__.py +62 -0
  76. sqlalchemy/engine/_processors_cy.cp315-win32.pyd +0 -0
  77. sqlalchemy/engine/_processors_cy.py +92 -0
  78. sqlalchemy/engine/_result_cy.cp315-win32.pyd +0 -0
  79. sqlalchemy/engine/_result_cy.py +711 -0
  80. sqlalchemy/engine/_row_cy.cp315-win32.pyd +0 -0
  81. sqlalchemy/engine/_row_cy.py +232 -0
  82. sqlalchemy/engine/_util_cy.cp315-win32.pyd +0 -0
  83. sqlalchemy/engine/_util_cy.py +136 -0
  84. sqlalchemy/engine/base.py +3357 -0
  85. sqlalchemy/engine/characteristics.py +155 -0
  86. sqlalchemy/engine/create.py +877 -0
  87. sqlalchemy/engine/cursor.py +2425 -0
  88. sqlalchemy/engine/default.py +2627 -0
  89. sqlalchemy/engine/events.py +965 -0
  90. sqlalchemy/engine/interfaces.py +3636 -0
  91. sqlalchemy/engine/mock.py +133 -0
  92. sqlalchemy/engine/processors.py +83 -0
  93. sqlalchemy/engine/reflection.py +2141 -0
  94. sqlalchemy/engine/result.py +2012 -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 +164 -0
  99. sqlalchemy/event/__init__.py +26 -0
  100. sqlalchemy/event/api.py +220 -0
  101. sqlalchemy/event/attr.py +675 -0
  102. sqlalchemy/event/base.py +473 -0
  103. sqlalchemy/event/legacy.py +259 -0
  104. sqlalchemy/event/registry.py +391 -0
  105. sqlalchemy/events.py +17 -0
  106. sqlalchemy/exc.py +939 -0
  107. sqlalchemy/ext/__init__.py +10 -0
  108. sqlalchemy/ext/associationproxy.py +2073 -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 +2006 -0
  116. sqlalchemy/ext/automap.py +1702 -0
  117. sqlalchemy/ext/baked.py +558 -0
  118. sqlalchemy/ext/compiler.py +601 -0
  119. sqlalchemy/ext/declarative/__init__.py +65 -0
  120. sqlalchemy/ext/declarative/extensions.py +561 -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 +440 -0
  127. sqlalchemy/ext/serializer.py +184 -0
  128. sqlalchemy/future/__init__.py +17 -0
  129. sqlalchemy/future/engine.py +15 -0
  130. sqlalchemy/inspection.py +188 -0
  131. sqlalchemy/log.py +279 -0
  132. sqlalchemy/orm/__init__.py +176 -0
  133. sqlalchemy/orm/_orm_constructors.py +2694 -0
  134. sqlalchemy/orm/_typing.py +180 -0
  135. sqlalchemy/orm/attributes.py +2868 -0
  136. sqlalchemy/orm/base.py +991 -0
  137. sqlalchemy/orm/bulk_persistence.py +2168 -0
  138. sqlalchemy/orm/clsregistry.py +630 -0
  139. sqlalchemy/orm/collections.py +1569 -0
  140. sqlalchemy/orm/context.py +3475 -0
  141. sqlalchemy/orm/decl_api.py +2283 -0
  142. sqlalchemy/orm/decl_base.py +2320 -0
  143. sqlalchemy/orm/dependency.py +1306 -0
  144. sqlalchemy/orm/descriptor_props.py +1183 -0
  145. sqlalchemy/orm/dynamic.py +306 -0
  146. sqlalchemy/orm/evaluator.py +378 -0
  147. sqlalchemy/orm/events.py +3387 -0
  148. sqlalchemy/orm/exc.py +237 -0
  149. sqlalchemy/orm/identity.py +302 -0
  150. sqlalchemy/orm/instrumentation.py +749 -0
  151. sqlalchemy/orm/interfaces.py +1595 -0
  152. sqlalchemy/orm/loading.py +1712 -0
  153. sqlalchemy/orm/mapped_collection.py +557 -0
  154. sqlalchemy/orm/mapper.py +4465 -0
  155. sqlalchemy/orm/path_registry.py +907 -0
  156. sqlalchemy/orm/persistence.py +1790 -0
  157. sqlalchemy/orm/properties.py +972 -0
  158. sqlalchemy/orm/query.py +3528 -0
  159. sqlalchemy/orm/relationships.py +3608 -0
  160. sqlalchemy/orm/scoping.py +2233 -0
  161. sqlalchemy/orm/session.py +5468 -0
  162. sqlalchemy/orm/state.py +1175 -0
  163. sqlalchemy/orm/state_changes.py +196 -0
  164. sqlalchemy/orm/strategies.py +3552 -0
  165. sqlalchemy/orm/strategy_options.py +2648 -0
  166. sqlalchemy/orm/sync.py +164 -0
  167. sqlalchemy/orm/unitofwork.py +797 -0
  168. sqlalchemy/orm/util.py +2461 -0
  169. sqlalchemy/orm/writeonly.py +701 -0
  170. sqlalchemy/pool/__init__.py +41 -0
  171. sqlalchemy/pool/base.py +1540 -0
  172. sqlalchemy/pool/events.py +375 -0
  173. sqlalchemy/pool/impl.py +583 -0
  174. sqlalchemy/py.typed +0 -0
  175. sqlalchemy/schema.py +75 -0
  176. sqlalchemy/sql/__init__.py +156 -0
  177. sqlalchemy/sql/_annotated_cols.py +402 -0
  178. sqlalchemy/sql/_cache_key_cy.cp315-win32.pyd +0 -0
  179. sqlalchemy/sql/_cache_key_cy.py +363 -0
  180. sqlalchemy/sql/_dml_constructors.py +132 -0
  181. sqlalchemy/sql/_elements_constructors.py +2190 -0
  182. sqlalchemy/sql/_orm_types.py +19 -0
  183. sqlalchemy/sql/_selectable_constructors.py +840 -0
  184. sqlalchemy/sql/_typing.py +500 -0
  185. sqlalchemy/sql/_util_cy.cp315-win32.pyd +0 -0
  186. sqlalchemy/sql/_util_cy.pxd +11 -0
  187. sqlalchemy/sql/_util_cy.py +127 -0
  188. sqlalchemy/sql/annotation.py +590 -0
  189. sqlalchemy/sql/base.py +2702 -0
  190. sqlalchemy/sql/cache_key.py +915 -0
  191. sqlalchemy/sql/coercions.py +1373 -0
  192. sqlalchemy/sql/compiler.py +8453 -0
  193. sqlalchemy/sql/crud.py +1816 -0
  194. sqlalchemy/sql/ddl.py +1962 -0
  195. sqlalchemy/sql/default_comparator.py +660 -0
  196. sqlalchemy/sql/dml.py +2018 -0
  197. sqlalchemy/sql/elements.py +6057 -0
  198. sqlalchemy/sql/events.py +458 -0
  199. sqlalchemy/sql/expression.py +171 -0
  200. sqlalchemy/sql/functions.py +2380 -0
  201. sqlalchemy/sql/lambdas.py +1442 -0
  202. sqlalchemy/sql/naming.py +204 -0
  203. sqlalchemy/sql/operators.py +2909 -0
  204. sqlalchemy/sql/roles.py +332 -0
  205. sqlalchemy/sql/schema.py +7075 -0
  206. sqlalchemy/sql/selectable.py +7634 -0
  207. sqlalchemy/sql/sqltypes.py +4130 -0
  208. sqlalchemy/sql/traversals.py +1041 -0
  209. sqlalchemy/sql/type_api.py +2450 -0
  210. sqlalchemy/sql/util.py +1496 -0
  211. sqlalchemy/sql/visitors.py +1153 -0
  212. sqlalchemy/testing/__init__.py +97 -0
  213. sqlalchemy/testing/assertions.py +1007 -0
  214. sqlalchemy/testing/assertsql.py +519 -0
  215. sqlalchemy/testing/asyncio.py +128 -0
  216. sqlalchemy/testing/cancellation.py +237 -0
  217. sqlalchemy/testing/config.py +440 -0
  218. sqlalchemy/testing/engines.py +482 -0
  219. sqlalchemy/testing/entities.py +117 -0
  220. sqlalchemy/testing/exclusions.py +501 -0
  221. sqlalchemy/testing/fixtures/__init__.py +30 -0
  222. sqlalchemy/testing/fixtures/base.py +426 -0
  223. sqlalchemy/testing/fixtures/mypy.py +247 -0
  224. sqlalchemy/testing/fixtures/orm.py +227 -0
  225. sqlalchemy/testing/fixtures/sql.py +538 -0
  226. sqlalchemy/testing/pickleable.py +155 -0
  227. sqlalchemy/testing/plugin/__init__.py +6 -0
  228. sqlalchemy/testing/plugin/bootstrap.py +50 -0
  229. sqlalchemy/testing/plugin/plugin_base.py +828 -0
  230. sqlalchemy/testing/plugin/pytestplugin.py +896 -0
  231. sqlalchemy/testing/profiles_file.py +350 -0
  232. sqlalchemy/testing/profiling.py +294 -0
  233. sqlalchemy/testing/provision.py +633 -0
  234. sqlalchemy/testing/requirements.py +1971 -0
  235. sqlalchemy/testing/schema.py +198 -0
  236. sqlalchemy/testing/suite/__init__.py +19 -0
  237. sqlalchemy/testing/suite/test_cte.py +237 -0
  238. sqlalchemy/testing/suite/test_ddl.py +420 -0
  239. sqlalchemy/testing/suite/test_dialect.py +776 -0
  240. sqlalchemy/testing/suite/test_insert.py +630 -0
  241. sqlalchemy/testing/suite/test_reflection.py +3815 -0
  242. sqlalchemy/testing/suite/test_results.py +660 -0
  243. sqlalchemy/testing/suite/test_rowcount.py +258 -0
  244. sqlalchemy/testing/suite/test_select.py +2112 -0
  245. sqlalchemy/testing/suite/test_sequence.py +317 -0
  246. sqlalchemy/testing/suite/test_table_via_select.py +686 -0
  247. sqlalchemy/testing/suite/test_types.py +2271 -0
  248. sqlalchemy/testing/suite/test_unicode_ddl.py +189 -0
  249. sqlalchemy/testing/suite/test_update_delete.py +139 -0
  250. sqlalchemy/testing/util.py +575 -0
  251. sqlalchemy/testing/warnings.py +52 -0
  252. sqlalchemy/types.py +75 -0
  253. sqlalchemy/util/__init__.py +165 -0
  254. sqlalchemy/util/_collections.py +688 -0
  255. sqlalchemy/util/_collections_cy.cp315-win32.pyd +0 -0
  256. sqlalchemy/util/_collections_cy.pxd +8 -0
  257. sqlalchemy/util/_collections_cy.py +516 -0
  258. sqlalchemy/util/_has_cython.py +48 -0
  259. sqlalchemy/util/_immutabledict_cy.cp315-win32.pyd +0 -0
  260. sqlalchemy/util/_immutabledict_cy.py +240 -0
  261. sqlalchemy/util/compat.py +298 -0
  262. sqlalchemy/util/concurrency.py +272 -0
  263. sqlalchemy/util/cython.py +95 -0
  264. sqlalchemy/util/deprecations.py +401 -0
  265. sqlalchemy/util/langhelpers.py +2797 -0
  266. sqlalchemy/util/preloaded.py +153 -0
  267. sqlalchemy/util/queue.py +304 -0
  268. sqlalchemy/util/tool_support.py +202 -0
  269. sqlalchemy/util/topological.py +120 -0
  270. sqlalchemy/util/typing.py +709 -0
  271. sqlalchemy-2.1.0rc1.dist-info/METADATA +270 -0
  272. sqlalchemy-2.1.0rc1.dist-info/RECORD +276 -0
  273. sqlalchemy-2.1.0rc1.dist-info/WHEEL +5 -0
  274. sqlalchemy-2.1.0rc1.dist-info/licenses/AUTHORS +30 -0
  275. sqlalchemy-2.1.0rc1.dist-info/licenses/LICENSE +19 -0
  276. sqlalchemy-2.1.0rc1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,500 @@
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 Tuple
24
+ from typing import Type
25
+ from typing import TYPE_CHECKING
26
+ from typing import TypeAlias
27
+ from typing import TypeVar
28
+ from typing import Union
29
+
30
+ from . import roles
31
+ from .. import exc
32
+ from .. import util
33
+ from ..inspection import Inspectable
34
+ from ..util.typing import TupleAny
35
+ from ..util.typing import TypeVarTuple
36
+ from ..util.typing import Unpack
37
+
38
+ if TYPE_CHECKING:
39
+ from datetime import date
40
+ from datetime import datetime
41
+ from datetime import time
42
+ from datetime import timedelta
43
+ from decimal import Decimal
44
+ from typing import TypeGuard
45
+ from uuid import UUID
46
+
47
+ from .base import Executable
48
+ from .compiler import Compiled
49
+ from .compiler import DDLCompiler
50
+ from .compiler import SQLCompiler
51
+ from .dml import UpdateBase
52
+ from .dml import ValuesBase
53
+ from .elements import ClauseElement
54
+ from .elements import ColumnElement
55
+ from .elements import KeyedColumnElement
56
+ from .elements import quoted_name
57
+ from .elements import SQLCoreOperations
58
+ from .elements import TextClause
59
+ from .lambdas import LambdaElement
60
+ from .roles import FromClauseRole
61
+ from .schema import Column
62
+ from .selectable import Alias
63
+ from .selectable import CompoundSelect
64
+ from .selectable import CTE
65
+ from .selectable import FromClause
66
+ from .selectable import Join
67
+ from .selectable import NamedFromClause
68
+ from .selectable import ReturnsRows
69
+ from .selectable import Select
70
+ from .selectable import Selectable
71
+ from .selectable import SelectBase
72
+ from .selectable import Subquery
73
+ from .selectable import TableClause
74
+ from .sqltypes import TableValueType
75
+ from .sqltypes import TupleType
76
+ from .type_api import TypeEngine
77
+ from ..engine import Connection
78
+ from ..engine import Dialect
79
+ from ..engine import Engine
80
+ from ..engine.mock import MockConnection
81
+
82
+ _T = TypeVar("_T", bound=Any)
83
+ _T_co = TypeVar("_T_co", bound=Any, covariant=True)
84
+ _Ts = TypeVarTuple("_Ts")
85
+ _Ts2 = TypeVarTuple("_Ts2")
86
+
87
+
88
+ _CE = TypeVar("_CE", bound="ColumnElement[Any]")
89
+
90
+ _CLE = TypeVar("_CLE", bound="ClauseElement")
91
+
92
+
93
+ class _HasClauseElement(Protocol, Generic[_T_co]):
94
+ """indicates a class that has a __clause_element__() method"""
95
+
96
+ def __clause_element__(self) -> roles.ExpressionElementRole[_T_co]: ...
97
+
98
+
99
+ class _CoreAdapterProto(Protocol):
100
+ """protocol for the ClauseAdapter/ColumnAdapter.traverse() method."""
101
+
102
+ def __call__(self, obj: _CE) -> _CE: ...
103
+
104
+
105
+ class _HasDialect(Protocol):
106
+ """protocol for Engine/Connection-like objects that have dialect
107
+ attribute.
108
+ """
109
+
110
+ @property
111
+ def dialect(self) -> Dialect: ...
112
+
113
+
114
+ # match column types that are not ORM entities
115
+ _NOT_ENTITY = TypeVar(
116
+ "_NOT_ENTITY",
117
+ int,
118
+ str,
119
+ bool,
120
+ "datetime",
121
+ "date",
122
+ "time",
123
+ "timedelta",
124
+ "UUID",
125
+ float,
126
+ "Decimal",
127
+ )
128
+
129
+ _StarOrOne = Literal["*", 1]
130
+
131
+ _MAYBE_ENTITY = TypeVar(
132
+ "_MAYBE_ENTITY",
133
+ roles.ColumnsClauseRole,
134
+ _StarOrOne,
135
+ Type[Any],
136
+ Inspectable[_HasClauseElement[Any]],
137
+ _HasClauseElement[Any],
138
+ )
139
+
140
+
141
+ # convention:
142
+ # XYZArgument - something that the end user is passing to a public API method
143
+ # XYZElement - the internal representation that we use for the thing.
144
+ # the coercions system is responsible for converting from XYZArgument to
145
+ # XYZElement.
146
+
147
+ _TextCoercedExpressionArgument = Union[
148
+ str,
149
+ "TextClause",
150
+ "ColumnElement[_T]",
151
+ _HasClauseElement[_T],
152
+ roles.ExpressionElementRole[_T],
153
+ ]
154
+
155
+ _ColumnsClauseArgument = Union[
156
+ roles.TypedColumnsClauseRole[_T],
157
+ roles.ColumnsClauseRole,
158
+ "SQLCoreOperations[_T]",
159
+ _StarOrOne,
160
+ Type[_T],
161
+ Inspectable[_HasClauseElement[_T]],
162
+ _HasClauseElement[_T],
163
+ ]
164
+ """open-ended SELECT columns clause argument.
165
+
166
+ Includes column expressions, tables, ORM mapped entities, a few literal values.
167
+
168
+ This type is used for lists of columns / entities to be returned in result
169
+ sets; select(...), insert().returning(...), etc.
170
+
171
+
172
+ """
173
+
174
+ _TypedColumnClauseArgument = Union[
175
+ roles.TypedColumnsClauseRole[_T],
176
+ "SQLCoreOperations[_T]",
177
+ Type[_T],
178
+ ]
179
+
180
+ _T0 = TypeVar("_T0", bound=Any)
181
+ _T1 = TypeVar("_T1", bound=Any)
182
+ _T2 = TypeVar("_T2", bound=Any)
183
+ _T3 = TypeVar("_T3", bound=Any)
184
+ _T4 = TypeVar("_T4", bound=Any)
185
+ _T5 = TypeVar("_T5", bound=Any)
186
+ _T6 = TypeVar("_T6", bound=Any)
187
+ _T7 = TypeVar("_T7", bound=Any)
188
+ _T8 = TypeVar("_T8", bound=Any)
189
+ _T9 = TypeVar("_T9", bound=Any)
190
+
191
+
192
+ _OnlyColumnArgument = Union[
193
+ "ColumnElement[_T]",
194
+ _HasClauseElement[_T],
195
+ roles.DMLColumnRole,
196
+ ]
197
+ """A narrow type that is looking for a ColumnClause (e.g. table column with a
198
+ name) or an ORM element that produces this.
199
+
200
+ This is used for constructs that need a named column to represent a
201
+ position in a selectable, like TextClause().columns() or values(...).
202
+
203
+ """
204
+
205
+ _ColumnExpressionArgument = Union[
206
+ "ColumnElement[_T]",
207
+ _HasClauseElement[_T],
208
+ "SQLCoreOperations[_T]",
209
+ roles.ExpressionElementRole[_T],
210
+ roles.TypedColumnsClauseRole[_T],
211
+ Callable[[], "ColumnElement[_T]"],
212
+ "LambdaElement",
213
+ ]
214
+ "See docs in public alias ColumnExpressionArgument."
215
+
216
+ ColumnExpressionArgument: TypeAlias = _ColumnExpressionArgument[_T]
217
+ """Narrower "column expression" argument.
218
+
219
+ This type is used for all the other "column" kinds of expressions that
220
+ typically represent a single SQL column expression, not a set of columns the
221
+ way a table or ORM entity does.
222
+
223
+ This includes ColumnElement, or ORM-mapped attributes that will have a
224
+ ``__clause_element__()`` method, it also has the ExpressionElementRole
225
+ overall which brings in the TextClause object also.
226
+
227
+ .. versionadded:: 2.0.13
228
+
229
+ """
230
+
231
+ _ColumnExpressionOrLiteralArgument = Union[Any, _ColumnExpressionArgument[_T]]
232
+
233
+ _ColumnExpressionOrStrLabelArgument = Union[str, _ColumnExpressionArgument[_T]]
234
+
235
+ _ByArgument = Union[
236
+ Iterable[_ColumnExpressionOrStrLabelArgument[Any]],
237
+ _ColumnExpressionOrStrLabelArgument[Any],
238
+ ]
239
+ """Used for keyword-based ``order_by`` and ``partition_by`` parameters."""
240
+
241
+
242
+ _InfoType = Dict[Any, Any]
243
+ """the .info dictionary accepted and used throughout Core /ORM"""
244
+
245
+ _FromClauseArgument = Union[
246
+ roles.FromClauseRole,
247
+ roles.TypedColumnsClauseRole[Any],
248
+ Type[Any],
249
+ Inspectable[_HasClauseElement[Any]],
250
+ _HasClauseElement[Any],
251
+ ]
252
+ """A FROM clause, like we would send to select().select_from().
253
+
254
+ Also accommodates ORM entities and related constructs.
255
+
256
+ """
257
+
258
+ _JoinTargetArgument = Union[_FromClauseArgument, roles.JoinTargetRole]
259
+ """target for join() builds on _FromClauseArgument to include additional
260
+ join target roles such as those which come from the ORM.
261
+
262
+ """
263
+
264
+ _OnClauseArgument = Union[_ColumnExpressionArgument[Any], roles.OnClauseRole]
265
+ """target for an ON clause, includes additional roles such as those which
266
+ come from the ORM.
267
+
268
+ """
269
+
270
+ _SelectStatementForCompoundArgument = Union[
271
+ "Select[Unpack[_Ts]]",
272
+ "CompoundSelect[Unpack[_Ts]]",
273
+ roles.CompoundElementRole,
274
+ ]
275
+ """SELECT statement acceptable by ``union()`` and other SQL set operations"""
276
+
277
+ _DMLColumnArgument = Union[
278
+ str,
279
+ _HasClauseElement[Any],
280
+ roles.DMLColumnRole,
281
+ "SQLCoreOperations[Any]",
282
+ ]
283
+ """A DML column expression. This is a "key" inside of insert().values(),
284
+ update().values(), and related.
285
+
286
+ These are usually strings or SQL table columns.
287
+
288
+ There's also edge cases like JSON expression assignment, which we would want
289
+ the DMLColumnRole to be able to accommodate.
290
+
291
+ """
292
+
293
+
294
+ _DMLKey = TypeVar("_DMLKey", bound=_DMLColumnArgument)
295
+ _DMLColumnKeyMapping = Mapping[_DMLKey, Any]
296
+
297
+
298
+ _DDLColumnArgument = Union[str, "Column[Any]", roles.DDLConstraintColumnRole]
299
+ """DDL column.
300
+
301
+ used for :class:`.PrimaryKeyConstraint`, :class:`.UniqueConstraint`, etc.
302
+
303
+ """
304
+
305
+ _DDLColumnReferenceArgument = Union[
306
+ _DDLColumnArgument,
307
+ Tuple[Optional[str], str, Optional[str]],
308
+ Tuple[str, Optional[str]],
309
+ ]
310
+ """DDL column reference, as used by :class:`.ForeignKey`.
311
+
312
+ In addition to the forms accepted by ``_DDLColumnArgument``, the target may
313
+ be given as a ``(schema, table_name, column_name)`` or ``(table_name,
314
+ column_name)`` tuple, which is the only form that can express a name that
315
+ itself contains a dot.
316
+
317
+ """
318
+
319
+ _DMLTableArgument = Union[
320
+ "TableClause",
321
+ "Join",
322
+ "Alias",
323
+ "CTE",
324
+ Type[Any],
325
+ Inspectable[_HasClauseElement[Any]],
326
+ _HasClauseElement[Any],
327
+ ]
328
+
329
+ _PropagateAttrsType = util.immutabledict[str, Any]
330
+
331
+ _TypeEngineArgument = Union[Type["TypeEngine[_T]"], "TypeEngine[_T]"]
332
+
333
+ _EquivalentColumnMap = Dict["ColumnElement[Any]", Set["ColumnElement[Any]"]]
334
+
335
+ _LimitOffsetType = Union[int, _ColumnExpressionArgument[int], None]
336
+
337
+ _AutoIncrementType = Union[bool, Literal["auto", "ignore_fk"]]
338
+
339
+ _CreateDropBind = Union["Engine", "Connection", "MockConnection"]
340
+
341
+ if TYPE_CHECKING:
342
+
343
+ def is_sql_compiler(c: Compiled) -> TypeGuard[SQLCompiler]: ...
344
+
345
+ def is_ddl_compiler(c: Compiled) -> TypeGuard[DDLCompiler]: ...
346
+
347
+ def is_named_from_clause(
348
+ t: FromClauseRole,
349
+ ) -> TypeGuard[NamedFromClause]: ...
350
+
351
+ def is_column_element(
352
+ c: ClauseElement,
353
+ ) -> TypeGuard[ColumnElement[Any]]: ...
354
+
355
+ def is_keyed_column_element(
356
+ c: ClauseElement,
357
+ ) -> TypeGuard[KeyedColumnElement[Any]]: ...
358
+
359
+ def is_text_clause(c: ClauseElement) -> TypeGuard[TextClause]: ...
360
+
361
+ def is_from_clause(c: ClauseElement) -> TypeGuard[FromClause]: ...
362
+
363
+ def is_tuple_type(t: TypeEngine[Any]) -> TypeGuard[TupleType]: ...
364
+
365
+ def is_table_value_type(
366
+ t: TypeEngine[Any],
367
+ ) -> TypeGuard[TableValueType]: ...
368
+
369
+ def is_selectable(t: Any) -> TypeGuard[Selectable]: ...
370
+
371
+ def is_select_base(
372
+ t: Union[Executable, ReturnsRows],
373
+ ) -> TypeGuard[SelectBase]: ...
374
+
375
+ def is_select_statement(
376
+ t: Union[Executable, ReturnsRows],
377
+ ) -> TypeGuard[Select[Unpack[TupleAny]]]: ...
378
+
379
+ def is_table(t: FromClause) -> TypeGuard[TableClause]: ...
380
+
381
+ def is_subquery(t: FromClause) -> TypeGuard[Subquery]: ...
382
+
383
+ def is_dml(c: ClauseElement) -> TypeGuard[UpdateBase]: ...
384
+
385
+ else:
386
+ is_sql_compiler = operator.attrgetter("is_sql")
387
+ is_ddl_compiler = operator.attrgetter("is_ddl")
388
+ is_named_from_clause = operator.attrgetter("named_with_column")
389
+ is_column_element = operator.attrgetter("_is_column_element")
390
+ is_keyed_column_element = operator.attrgetter("_is_keyed_column_element")
391
+ is_text_clause = operator.attrgetter("_is_text_clause")
392
+ is_from_clause = operator.attrgetter("_is_from_clause")
393
+ is_tuple_type = operator.attrgetter("_is_tuple_type")
394
+ is_table_value_type = operator.attrgetter("_is_table_value")
395
+ is_selectable = operator.attrgetter("is_selectable")
396
+ is_select_base = operator.attrgetter("_is_select_base")
397
+ is_select_statement = operator.attrgetter("_is_select_statement")
398
+ is_table = operator.attrgetter("_is_table")
399
+ is_subquery = operator.attrgetter("_is_subquery")
400
+ is_dml = operator.attrgetter("is_dml")
401
+
402
+
403
+ def has_schema_attr(t: FromClauseRole) -> TypeGuard[TableClause]:
404
+ return hasattr(t, "schema")
405
+
406
+
407
+ def is_quoted_name(s: str) -> TypeGuard[quoted_name]:
408
+ return hasattr(s, "quote")
409
+
410
+
411
+ def is_has_clause_element(s: object) -> TypeGuard[_HasClauseElement[Any]]:
412
+ return hasattr(s, "__clause_element__")
413
+
414
+
415
+ def is_insert_update(c: ClauseElement) -> TypeGuard[ValuesBase]:
416
+ return c.is_dml and (c.is_insert or c.is_update) # type: ignore[attr-defined] # noqa: E501
417
+
418
+
419
+ def _no_kw() -> exc.ArgumentError:
420
+ return exc.ArgumentError(
421
+ "Additional keyword arguments are not accepted by this "
422
+ "function/method. The presence of **kw is for pep-484 typing purposes"
423
+ )
424
+
425
+
426
+ def _unexpected_kw(methname: str, kw: Dict[str, Any]) -> NoReturn:
427
+ k = list(kw)[0]
428
+ raise TypeError(f"{methname} got an unexpected keyword argument '{k}'")
429
+
430
+
431
+ @overload
432
+ def Nullable(
433
+ val: "SQLCoreOperations[_T]",
434
+ ) -> "SQLCoreOperations[Optional[_T]]": ...
435
+
436
+
437
+ @overload
438
+ def Nullable(
439
+ val: roles.ExpressionElementRole[_T],
440
+ ) -> roles.ExpressionElementRole[Optional[_T]]: ...
441
+
442
+
443
+ @overload
444
+ def Nullable(val: Type[_T]) -> Type[Optional[_T]]: ...
445
+
446
+
447
+ def Nullable(
448
+ val: _TypedColumnClauseArgument[_T],
449
+ ) -> _TypedColumnClauseArgument[Optional[_T]]:
450
+ """Types a column or ORM class as nullable.
451
+
452
+ This can be used in select and other contexts to express that the value of
453
+ a column can be null, for example due to an outer join::
454
+
455
+ stmt1 = select(A, Nullable(B)).outerjoin(A.bs)
456
+ stmt2 = select(A.data, Nullable(B.data)).outerjoin(A.bs)
457
+
458
+ At runtime this method returns the input unchanged.
459
+
460
+ .. versionadded:: 2.0.20
461
+ """
462
+ return val
463
+
464
+
465
+ @overload
466
+ def NotNullable(
467
+ val: "SQLCoreOperations[Optional[_T]]",
468
+ ) -> "SQLCoreOperations[_T]": ...
469
+
470
+
471
+ @overload
472
+ def NotNullable(
473
+ val: roles.ExpressionElementRole[Optional[_T]],
474
+ ) -> roles.ExpressionElementRole[_T]: ...
475
+
476
+
477
+ @overload
478
+ def NotNullable(val: Type[Optional[_T]]) -> Type[_T]: ...
479
+
480
+
481
+ @overload
482
+ def NotNullable(val: Optional[Type[_T]]) -> Type[_T]: ...
483
+
484
+
485
+ def NotNullable(
486
+ val: Union[_TypedColumnClauseArgument[Optional[_T]], Optional[Type[_T]]],
487
+ ) -> _TypedColumnClauseArgument[_T]:
488
+ """Types a column or ORM class as not nullable.
489
+
490
+ This can be used in select and other contexts to express that the value of
491
+ a column cannot be null, for example due to a where condition on a
492
+ nullable column::
493
+
494
+ stmt = select(NotNullable(A.value)).where(A.value.is_not(None))
495
+
496
+ At runtime this method returns the input unchanged.
497
+
498
+ .. versionadded:: 2.0.20
499
+ """
500
+ return val # type: ignore[return-value]
Binary file
@@ -0,0 +1,11 @@
1
+ # sql/_util_cy.pxd
2
+ # Copyright (C) 2005-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
+ cdef class anon_map(dict):
9
+ cdef unsigned int _index
10
+
11
+ cdef inline object _add_missing(self, object key)
@@ -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, /) -> object:
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]