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
sqlalchemy/orm/base.py ADDED
@@ -0,0 +1,991 @@
1
+ # orm/base.py
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
+ """Constants and rudimental functions used throughout the ORM."""
9
+
10
+ from __future__ import annotations
11
+
12
+ from enum import Enum
13
+ import operator
14
+ import typing
15
+ from typing import Any
16
+ from typing import Callable
17
+ from typing import cast
18
+ from typing import Dict
19
+ from typing import Generic
20
+ from typing import Literal
21
+ from typing import no_type_check
22
+ from typing import Optional
23
+ from typing import overload
24
+ from typing import Tuple
25
+ from typing import Type
26
+ from typing import TYPE_CHECKING
27
+ from typing import TypeVar
28
+ from typing import Union
29
+
30
+ from . import exc
31
+ from ._typing import _HasPathString
32
+ from ._typing import _O
33
+ from ._typing import insp_is_mapper
34
+ from .. import exc as sa_exc
35
+ from .. import inspection
36
+ from .. import util
37
+ from ..sql import roles
38
+ from ..sql._typing import _T
39
+ from ..sql._typing import _T_co
40
+ from ..sql.elements import SQLColumnExpression
41
+ from ..sql.elements import SQLCoreOperations
42
+ from ..util import FastIntFlag
43
+ from ..util.langhelpers import TypingOnly
44
+
45
+ if typing.TYPE_CHECKING:
46
+ from ._typing import _EntityType
47
+ from ._typing import _ExternalEntityType
48
+ from ._typing import _InternalEntityType
49
+ from .attributes import InstrumentedAttribute
50
+ from .dynamic import AppenderQuery
51
+ from .instrumentation import ClassManager
52
+ from .interfaces import PropComparator
53
+ from .mapper import Mapper
54
+ from .properties import MappedColumn
55
+ from .state import InstanceState
56
+ from .util import AliasedClass
57
+ from .writeonly import WriteOnlyCollection
58
+ from ..sql._annotated_cols import TypedColumns
59
+ from ..sql._typing import _ColumnExpressionArgument
60
+ from ..sql._typing import _InfoType
61
+ from ..sql.elements import ColumnElement
62
+ from ..sql.operators import OperatorType
63
+ from ..sql.schema import Column
64
+
65
+
66
+ class LoaderCallableStatus(Enum):
67
+ PASSIVE_NO_RESULT = 0
68
+ """Symbol returned by a loader callable or other attribute/history
69
+ retrieval operation when a value could not be determined, based
70
+ on loader callable flags.
71
+ """
72
+
73
+ PASSIVE_CLASS_MISMATCH = 1
74
+ """Symbol indicating that an object is locally present for a given
75
+ primary key identity but it is not of the requested class. The
76
+ return value is therefore None and no SQL should be emitted."""
77
+
78
+ ATTR_WAS_SET = 2
79
+ """Symbol returned by a loader callable to indicate the
80
+ retrieved value, or values, were assigned to their attributes
81
+ on the target object.
82
+ """
83
+
84
+ ATTR_EMPTY = 3
85
+ """Symbol used internally to indicate an attribute had no callable."""
86
+
87
+ NO_VALUE = 4
88
+ """Symbol which may be placed as the 'previous' value of an attribute,
89
+ indicating no value was loaded for an attribute when it was modified,
90
+ and flags indicated we were not to load it.
91
+ """
92
+
93
+ NEVER_SET = NO_VALUE
94
+ """
95
+ Synonymous with NO_VALUE
96
+
97
+ .. versionchanged:: 1.4 NEVER_SET was merged with NO_VALUE
98
+
99
+ """
100
+
101
+ DONT_SET = 5
102
+
103
+
104
+ (
105
+ PASSIVE_NO_RESULT,
106
+ PASSIVE_CLASS_MISMATCH,
107
+ ATTR_WAS_SET,
108
+ ATTR_EMPTY,
109
+ NO_VALUE,
110
+ DONT_SET,
111
+ ) = tuple(LoaderCallableStatus)
112
+
113
+ NEVER_SET = NO_VALUE
114
+
115
+
116
+ class PassiveFlag(FastIntFlag):
117
+ """Bitflag interface that passes options onto loader callables"""
118
+
119
+ NO_CHANGE = 0
120
+ """No callables or SQL should be emitted on attribute access
121
+ and no state should change
122
+ """
123
+
124
+ CALLABLES_OK = 1
125
+ """Loader callables can be fired off if a value
126
+ is not present.
127
+ """
128
+
129
+ SQL_OK = 2
130
+ """Loader callables can emit SQL at least on scalar value attributes."""
131
+
132
+ RELATED_OBJECT_OK = 4
133
+ """Callables can use SQL to load related objects as well
134
+ as scalar value attributes.
135
+ """
136
+
137
+ INIT_OK = 8
138
+ """Attributes should be initialized with a blank
139
+ value (None or an empty collection) upon get, if no other
140
+ value can be obtained.
141
+ """
142
+
143
+ NON_PERSISTENT_OK = 16
144
+ """Callables can be emitted if the parent is not persistent."""
145
+
146
+ LOAD_AGAINST_COMMITTED = 32
147
+ """Callables should use committed values as primary/foreign keys during a
148
+ load.
149
+ """
150
+
151
+ NO_AUTOFLUSH = 64
152
+ """Loader callables should disable autoflush."""
153
+
154
+ NO_RAISE = 128
155
+ """Loader callables should not raise any assertions"""
156
+
157
+ DEFERRED_HISTORY_LOAD = 256
158
+ """indicates special load of the previous value of an attribute"""
159
+
160
+ INCLUDE_PENDING_MUTATIONS = 512
161
+
162
+ # pre-packaged sets of flags used as inputs
163
+ PASSIVE_OFF = (
164
+ RELATED_OBJECT_OK | NON_PERSISTENT_OK | INIT_OK | CALLABLES_OK | SQL_OK
165
+ )
166
+ "Callables can be emitted in all cases."
167
+
168
+ PASSIVE_RETURN_NO_VALUE = PASSIVE_OFF ^ INIT_OK
169
+ """PASSIVE_OFF ^ INIT_OK"""
170
+
171
+ PASSIVE_NO_INITIALIZE = PASSIVE_RETURN_NO_VALUE ^ CALLABLES_OK
172
+ "PASSIVE_RETURN_NO_VALUE ^ CALLABLES_OK"
173
+
174
+ PASSIVE_NO_FETCH = PASSIVE_OFF ^ SQL_OK
175
+ "PASSIVE_OFF ^ SQL_OK"
176
+
177
+ PASSIVE_NO_FETCH_RELATED = PASSIVE_OFF ^ RELATED_OBJECT_OK
178
+ "PASSIVE_OFF ^ RELATED_OBJECT_OK"
179
+
180
+ PASSIVE_ONLY_PERSISTENT = PASSIVE_OFF ^ NON_PERSISTENT_OK
181
+ "PASSIVE_OFF ^ NON_PERSISTENT_OK"
182
+
183
+ PASSIVE_MERGE = PASSIVE_OFF | NO_RAISE
184
+ """PASSIVE_OFF | NO_RAISE
185
+
186
+ Symbol used specifically for session.merge() and similar cases
187
+
188
+ """
189
+
190
+
191
+ (
192
+ NO_CHANGE,
193
+ CALLABLES_OK,
194
+ SQL_OK,
195
+ RELATED_OBJECT_OK,
196
+ INIT_OK,
197
+ NON_PERSISTENT_OK,
198
+ LOAD_AGAINST_COMMITTED,
199
+ NO_AUTOFLUSH,
200
+ NO_RAISE,
201
+ DEFERRED_HISTORY_LOAD,
202
+ INCLUDE_PENDING_MUTATIONS,
203
+ PASSIVE_OFF,
204
+ PASSIVE_RETURN_NO_VALUE,
205
+ PASSIVE_NO_INITIALIZE,
206
+ PASSIVE_NO_FETCH,
207
+ PASSIVE_NO_FETCH_RELATED,
208
+ PASSIVE_ONLY_PERSISTENT,
209
+ PASSIVE_MERGE,
210
+ ) = PassiveFlag.__members__.values()
211
+
212
+ DEFAULT_MANAGER_ATTR = "_sa_class_manager"
213
+ DEFAULT_STATE_ATTR = "_sa_instance_state"
214
+
215
+
216
+ class EventConstants(Enum):
217
+ EXT_CONTINUE = 1
218
+ EXT_STOP = 2
219
+ EXT_SKIP = 3
220
+ NO_KEY = 4
221
+ """indicates an :class:`.AttributeEvent` event that did not have any
222
+ key argument.
223
+
224
+ .. versionadded:: 2.0
225
+
226
+ """
227
+
228
+
229
+ EXT_CONTINUE, EXT_STOP, EXT_SKIP, NO_KEY = tuple(EventConstants)
230
+
231
+
232
+ class RelationshipDirection(Enum):
233
+ """enumeration which indicates the 'direction' of a
234
+ :class:`_orm.RelationshipProperty`.
235
+
236
+ :class:`.RelationshipDirection` is accessible from the
237
+ :attr:`_orm.Relationship.direction` attribute of
238
+ :class:`_orm.RelationshipProperty`.
239
+
240
+ """
241
+
242
+ ONETOMANY = 1
243
+ """Indicates the one-to-many direction for a :func:`_orm.relationship`.
244
+
245
+ This symbol is typically used by the internals but may be exposed within
246
+ certain API features.
247
+
248
+ """
249
+
250
+ MANYTOONE = 2
251
+ """Indicates the many-to-one direction for a :func:`_orm.relationship`.
252
+
253
+ This symbol is typically used by the internals but may be exposed within
254
+ certain API features.
255
+
256
+ """
257
+
258
+ MANYTOMANY = 3
259
+ """Indicates the many-to-many direction for a :func:`_orm.relationship`.
260
+
261
+ This symbol is typically used by the internals but may be exposed within
262
+ certain API features.
263
+
264
+ """
265
+
266
+
267
+ ONETOMANY, MANYTOONE, MANYTOMANY = tuple(RelationshipDirection)
268
+
269
+
270
+ class InspectionAttrExtensionType(Enum):
271
+ """Symbols indicating the type of extension that a
272
+ :class:`.InspectionAttr` is part of."""
273
+
274
+
275
+ class NotExtension(InspectionAttrExtensionType):
276
+ NOT_EXTENSION = "not_extension"
277
+ """Symbol indicating an :class:`InspectionAttr` that's
278
+ not part of sqlalchemy.ext.
279
+
280
+ Is assigned to the :attr:`.InspectionAttr.extension_type`
281
+ attribute.
282
+
283
+ """
284
+
285
+
286
+ _never_set = frozenset([NEVER_SET])
287
+
288
+ _none_set = frozenset([None, NEVER_SET, PASSIVE_NO_RESULT])
289
+
290
+ _none_only_set = frozenset([None])
291
+
292
+ _SET_DEFERRED_EXPIRED = util.symbol("SET_DEFERRED_EXPIRED")
293
+
294
+ _DEFER_FOR_STATE = util.symbol("DEFER_FOR_STATE")
295
+
296
+ _RAISE_FOR_STATE = util.symbol("RAISE_FOR_STATE")
297
+
298
+
299
+ _F = TypeVar("_F", bound=Callable[..., Any])
300
+ _Self = TypeVar("_Self")
301
+
302
+
303
+ def _assertions(
304
+ *assertions: Any,
305
+ ) -> Callable[[_F], _F]:
306
+ @util.decorator
307
+ def generate(fn: _F, self: _Self, *args: Any, **kw: Any) -> _Self:
308
+ for assertion in assertions:
309
+ assertion(self, fn.__name__)
310
+ fn(self, *args, **kw)
311
+ return self
312
+
313
+ return generate
314
+
315
+
316
+ if TYPE_CHECKING:
317
+
318
+ def manager_of_class(cls: Type[_O]) -> ClassManager[_O]: ...
319
+
320
+ @overload
321
+ def opt_manager_of_class(cls: AliasedClass[Any]) -> None: ...
322
+
323
+ @overload
324
+ def opt_manager_of_class(
325
+ cls: _ExternalEntityType[_O],
326
+ ) -> Optional[ClassManager[_O]]: ...
327
+
328
+ def opt_manager_of_class(
329
+ cls: _ExternalEntityType[_O],
330
+ ) -> Optional[ClassManager[_O]]: ...
331
+
332
+ def instance_state(instance: _O) -> InstanceState[_O]: ...
333
+
334
+ def instance_dict(instance: object) -> Dict[str, Any]: ...
335
+
336
+ else:
337
+ # these can be replaced by sqlalchemy.ext.instrumentation
338
+ # if augmented class instrumentation is enabled.
339
+
340
+ def manager_of_class(cls):
341
+ try:
342
+ return cls.__dict__[DEFAULT_MANAGER_ATTR]
343
+ except KeyError as ke:
344
+ raise exc.UnmappedClassError(
345
+ cls, f"Can't locate an instrumentation manager for class {cls}"
346
+ ) from ke
347
+
348
+ def opt_manager_of_class(cls):
349
+ return cls.__dict__.get(DEFAULT_MANAGER_ATTR)
350
+
351
+ instance_state = operator.attrgetter(DEFAULT_STATE_ATTR)
352
+
353
+ instance_dict = operator.attrgetter("__dict__")
354
+
355
+
356
+ def instance_str(instance: object) -> str:
357
+ """Return a string describing an instance."""
358
+
359
+ return state_str(instance_state(instance))
360
+
361
+
362
+ def state_str(state: InstanceState[Any]) -> str:
363
+ """Return a string describing an instance via its InstanceState."""
364
+
365
+ if state is None:
366
+ return "None"
367
+ else:
368
+ return "<%s at 0x%x>" % (state.class_.__name__, id(state.obj()))
369
+
370
+
371
+ def state_class_str(state: InstanceState[Any]) -> str:
372
+ """Return a string describing an instance's class via its
373
+ InstanceState.
374
+ """
375
+
376
+ if state is None:
377
+ return "None"
378
+ else:
379
+ return "<%s>" % (state.class_.__name__,)
380
+
381
+
382
+ def attribute_str(instance: object, attribute: str) -> str:
383
+ return instance_str(instance) + "." + attribute
384
+
385
+
386
+ def state_attribute_str(state: InstanceState[Any], attribute: str) -> str:
387
+ return state_str(state) + "." + attribute
388
+
389
+
390
+ def entity_str(entity: Any) -> str:
391
+ """Return a user-facing string for a mapped entity, such as a mapped
392
+ class, :class:`_orm.Mapper`, or :func:`_orm.aliased` construct.
393
+
394
+ Also accepts a :class:`_orm.PathRegistry` directly, which is itself
395
+ ``inspect()``-able and implements ``path_string()``; in that case
396
+ this is equivalent to calling
397
+ :meth:`_orm.PathRegistry.path_string` directly.
398
+
399
+ """
400
+ return cast(_HasPathString, inspection.inspect(entity)).path_string()
401
+
402
+
403
+ def object_mapper(instance: _T) -> Mapper[_T]:
404
+ """Given an object, return the primary Mapper associated with the object
405
+ instance.
406
+
407
+ Raises :class:`sqlalchemy.orm.exc.UnmappedInstanceError`
408
+ if no mapping is configured.
409
+
410
+ This function is available via the inspection system as::
411
+
412
+ inspect(instance).mapper
413
+
414
+ Using the inspection system will raise
415
+ :class:`sqlalchemy.exc.NoInspectionAvailable` if the instance is
416
+ not part of a mapping.
417
+
418
+ """
419
+ return object_state(instance).mapper
420
+
421
+
422
+ def object_state(instance: _T) -> InstanceState[_T]:
423
+ """Given an object, return the :class:`.InstanceState`
424
+ associated with the object.
425
+
426
+ Raises :class:`sqlalchemy.orm.exc.UnmappedInstanceError`
427
+ if no mapping is configured.
428
+
429
+ Equivalent functionality is available via the :func:`_sa.inspect`
430
+ function as::
431
+
432
+ inspect(instance)
433
+
434
+ Using the inspection system will raise
435
+ :class:`sqlalchemy.exc.NoInspectionAvailable` if the instance is
436
+ not part of a mapping.
437
+
438
+ """
439
+ state = _inspect_mapped_object(instance)
440
+ if state is None:
441
+ raise exc.UnmappedInstanceError(instance)
442
+ else:
443
+ return state
444
+
445
+
446
+ @inspection._inspects(object)
447
+ def _inspect_mapped_object(instance: _T) -> Optional[InstanceState[_T]]:
448
+ try:
449
+ return instance_state(instance)
450
+ except (exc.UnmappedClassError,) + exc.NO_STATE:
451
+ return None
452
+
453
+
454
+ def _class_to_mapper(
455
+ class_or_mapper: Union[Mapper[_T], Type[_T]],
456
+ ) -> Mapper[_T]:
457
+ # can't get mypy to see an overload for this
458
+ insp = inspection.inspect(class_or_mapper, False)
459
+ if insp is not None:
460
+ return insp.mapper # type: ignore[no-any-return]
461
+ else:
462
+ assert isinstance(class_or_mapper, type)
463
+ raise exc.UnmappedClassError(class_or_mapper)
464
+
465
+
466
+ def _mapper_or_none(
467
+ entity: Union[Type[_T], _InternalEntityType[_T]],
468
+ ) -> Optional[Mapper[_T]]:
469
+ """Return the :class:`_orm.Mapper` for the given class or None if the
470
+ class is not mapped.
471
+ """
472
+
473
+ # can't get mypy to see an overload for this
474
+ insp = inspection.inspect(entity, False)
475
+ if insp is not None:
476
+ return insp.mapper # type: ignore[no-any-return]
477
+ else:
478
+ return None
479
+
480
+
481
+ def _is_mapped_class(entity: Any) -> bool:
482
+ """Return True if the given object is a mapped class,
483
+ :class:`_orm.Mapper`, or :class:`.AliasedClass`.
484
+ """
485
+
486
+ insp = inspection.inspect(entity, False)
487
+ return (
488
+ insp is not None
489
+ and not insp.is_clause_element
490
+ and (insp.is_mapper or insp.is_aliased_class)
491
+ )
492
+
493
+
494
+ def _is_aliased_class(entity: Any) -> bool:
495
+ insp = inspection.inspect(entity, False)
496
+ return insp is not None and getattr(insp, "is_aliased_class", False)
497
+
498
+
499
+ @no_type_check
500
+ def _entity_descriptor(entity: _EntityType[Any], key: str) -> Any:
501
+ """Return a class attribute given an entity and string name.
502
+
503
+ May return :class:`.InstrumentedAttribute` or user-defined
504
+ attribute.
505
+
506
+ """
507
+ insp = inspection.inspect(entity)
508
+ if insp.is_selectable:
509
+ description = entity
510
+ entity = insp.c
511
+ elif insp.is_aliased_class:
512
+ entity = insp.entity
513
+ description = entity
514
+ elif hasattr(insp, "mapper"):
515
+ description = entity = insp.mapper.class_
516
+ else:
517
+ description = entity
518
+
519
+ try:
520
+ return getattr(entity, key)
521
+ except AttributeError as err:
522
+ raise sa_exc.InvalidRequestError(
523
+ "Entity '%s' has no property '%s'" % (description, key)
524
+ ) from err
525
+
526
+
527
+ if TYPE_CHECKING:
528
+
529
+ def _state_mapper(state: InstanceState[_O]) -> Mapper[_O]: ...
530
+
531
+ else:
532
+ _state_mapper = util.dottedgetter("manager.mapper")
533
+
534
+
535
+ def _inspect_mapped_class(
536
+ class_: Type[_O], configure: bool = False
537
+ ) -> Optional[Mapper[_O]]:
538
+ try:
539
+ class_manager = opt_manager_of_class(class_)
540
+ if class_manager is None or not class_manager.is_mapped:
541
+ return None
542
+ mapper = class_manager.mapper
543
+ except exc.NO_STATE:
544
+ return None
545
+ else:
546
+ if configure:
547
+ mapper._check_configure()
548
+ return mapper
549
+
550
+
551
+ def _parse_mapper_argument(arg: Union[Mapper[_O], Type[_O]]) -> Mapper[_O]:
552
+ insp = inspection.inspect(arg, raiseerr=False)
553
+ if insp_is_mapper(insp):
554
+ return insp
555
+
556
+ raise sa_exc.ArgumentError(f"Mapper or mapped class expected, got {arg!r}")
557
+
558
+
559
+ def class_mapper(class_: Type[_O], configure: bool = True) -> Mapper[_O]:
560
+ """Given a class, return the primary :class:`_orm.Mapper` associated
561
+ with the key.
562
+
563
+ Raises :exc:`.UnmappedClassError` if no mapping is configured
564
+ on the given class, or :exc:`.ArgumentError` if a non-class
565
+ object is passed.
566
+
567
+ Equivalent functionality is available via the :func:`_sa.inspect`
568
+ function as::
569
+
570
+ inspect(some_mapped_class)
571
+
572
+ Using the inspection system will raise
573
+ :class:`sqlalchemy.exc.NoInspectionAvailable` if the class is not mapped.
574
+
575
+ """
576
+ mapper = _inspect_mapped_class(class_, configure=configure)
577
+ if mapper is None:
578
+ if not isinstance(class_, type):
579
+ raise sa_exc.ArgumentError(
580
+ "Class object expected, got '%r'." % (class_,)
581
+ )
582
+ raise exc.UnmappedClassError(class_)
583
+ else:
584
+ return mapper
585
+
586
+
587
+ class InspectionAttr:
588
+ """A base class applied to all ORM objects and attributes that are
589
+ related to things that can be returned by the :func:`_sa.inspect` function.
590
+
591
+ The attributes defined here allow the usage of simple boolean
592
+ checks to test basic facts about the object returned.
593
+
594
+ While the boolean checks here are basically the same as using
595
+ the Python isinstance() function, the flags here can be used without
596
+ the need to import all of these classes, and also such that
597
+ the SQLAlchemy class system can change while leaving the flags
598
+ here intact for forwards-compatibility.
599
+
600
+ """
601
+
602
+ __slots__: Tuple[str, ...] = ()
603
+
604
+ is_selectable = False
605
+ """Return True if this object is an instance of
606
+ :class:`_expression.Selectable`."""
607
+
608
+ is_aliased_class = False
609
+ """True if this object is an instance of :class:`.AliasedClass`."""
610
+
611
+ is_instance = False
612
+ """True if this object is an instance of :class:`.InstanceState`."""
613
+
614
+ is_mapper = False
615
+ """True if this object is an instance of :class:`_orm.Mapper`."""
616
+
617
+ is_bundle = False
618
+ """True if this object is an instance of :class:`.Bundle`."""
619
+
620
+ is_property = False
621
+ """True if this object is an instance of :class:`.MapperProperty`."""
622
+
623
+ is_attribute = False
624
+ """True if this object is a Python :term:`descriptor`.
625
+
626
+ This can refer to one of many types. Usually a
627
+ :class:`.QueryableAttribute` which handles attributes events on behalf
628
+ of a :class:`.MapperProperty`. But can also be an extension type
629
+ such as :class:`.AssociationProxy` or :class:`.hybrid_property`.
630
+ The :attr:`.InspectionAttr.extension_type` will refer to a constant
631
+ identifying the specific subtype.
632
+
633
+ .. seealso::
634
+
635
+ :attr:`_orm.Mapper.all_orm_descriptors`
636
+
637
+ """
638
+
639
+ _is_internal_proxy = False
640
+ """True if this object is an internal proxy object."""
641
+
642
+ is_clause_element = False
643
+ """True if this object is an instance of
644
+ :class:`_expression.ClauseElement`."""
645
+
646
+ extension_type: InspectionAttrExtensionType = NotExtension.NOT_EXTENSION
647
+ """The extension type, if any.
648
+ Defaults to :attr:`.interfaces.NotExtension.NOT_EXTENSION`
649
+
650
+ .. seealso::
651
+
652
+ :class:`.HybridExtensionType`
653
+
654
+ :class:`.AssociationProxyExtensionType`
655
+
656
+ """
657
+
658
+
659
+ class InspectionAttrInfo(InspectionAttr):
660
+ """Adds the ``.info`` attribute to :class:`.InspectionAttr`.
661
+
662
+ The rationale for :class:`.InspectionAttr` vs. :class:`.InspectionAttrInfo`
663
+ is that the former is compatible as a mixin for classes that specify
664
+ ``__slots__``; this is essentially an implementation artifact.
665
+
666
+ """
667
+
668
+ __slots__ = ()
669
+
670
+ @util.ro_memoized_property
671
+ def info(self) -> _InfoType:
672
+ """Info dictionary associated with the object, allowing user-defined
673
+ data to be associated with this :class:`.InspectionAttr`.
674
+
675
+ The dictionary is generated when first accessed. Alternatively,
676
+ it can be specified as a constructor argument to the
677
+ :func:`.column_property`, :func:`_orm.relationship`, or
678
+ :func:`.composite`
679
+ functions.
680
+
681
+ .. seealso::
682
+
683
+ :attr:`.QueryableAttribute.info`
684
+
685
+ :attr:`.SchemaItem.info`
686
+
687
+ """
688
+ return {}
689
+
690
+
691
+ class SQLORMOperations(SQLCoreOperations[_T_co], TypingOnly):
692
+ __slots__ = ()
693
+
694
+ if typing.TYPE_CHECKING:
695
+
696
+ def of_type(
697
+ self, class_: _EntityType[Any]
698
+ ) -> PropComparator[_T_co]: ...
699
+
700
+ def and_(
701
+ self, *criteria: _ColumnExpressionArgument[bool]
702
+ ) -> PropComparator[bool]: ...
703
+
704
+ def any( # noqa: A001
705
+ self,
706
+ criterion: Optional[_ColumnExpressionArgument[bool]] = None,
707
+ **kwargs: Any,
708
+ ) -> ColumnElement[bool]: ...
709
+
710
+ def has(
711
+ self,
712
+ criterion: Optional[_ColumnExpressionArgument[bool]] = None,
713
+ **kwargs: Any,
714
+ ) -> ColumnElement[bool]: ...
715
+
716
+
717
+ class ORMDescriptor(Generic[_T_co], TypingOnly):
718
+ """Represent any Python descriptor that provides a SQL expression
719
+ construct at the class level."""
720
+
721
+ __slots__ = ()
722
+
723
+ if typing.TYPE_CHECKING:
724
+
725
+ @overload
726
+ def __get__(
727
+ self, instance: Any, owner: Literal[None]
728
+ ) -> ORMDescriptor[_T_co]: ...
729
+
730
+ @overload
731
+ def __get__(
732
+ self, instance: Literal[None], owner: Any
733
+ ) -> SQLCoreOperations[_T_co]: ...
734
+
735
+ @overload
736
+ def __get__(self, instance: object, owner: Any) -> _T_co: ...
737
+
738
+ def __get__(
739
+ self, instance: object, owner: Any
740
+ ) -> Union[ORMDescriptor[_T_co], SQLCoreOperations[_T_co], _T_co]: ...
741
+
742
+
743
+ class _MappedAnnotationBase(Generic[_T_co], TypingOnly):
744
+ """common class for Mapped and similar ORM container classes.
745
+
746
+ these are classes that can appear on the left side of an ORM declarative
747
+ mapping, containing a mapped class or in some cases a collection
748
+ surrounding a mapped class.
749
+
750
+ """
751
+
752
+ __slots__ = ()
753
+
754
+
755
+ class SQLORMExpression(
756
+ SQLORMOperations[_T_co], SQLColumnExpression[_T_co], TypingOnly
757
+ ):
758
+ """A type that may be used to indicate any ORM-level attribute or
759
+ object that acts in place of one, in the context of SQL expression
760
+ construction.
761
+
762
+ :class:`.SQLORMExpression` extends from the Core
763
+ :class:`.SQLColumnExpression` to add additional SQL methods that are ORM
764
+ specific, such as :meth:`.PropComparator.of_type`, and is part of the bases
765
+ for :class:`.InstrumentedAttribute`. It may be used in :pep:`484` typing to
766
+ indicate arguments or return values that should behave as ORM-level
767
+ attribute expressions.
768
+
769
+ .. versionadded:: 2.0.0b4
770
+
771
+
772
+ """
773
+
774
+ __slots__ = ()
775
+
776
+
777
+ class Mapped(
778
+ SQLORMExpression[_T_co],
779
+ ORMDescriptor[_T_co],
780
+ _MappedAnnotationBase[_T_co],
781
+ roles.DDLConstraintColumnRole,
782
+ ):
783
+ """Represent an ORM mapped attribute on a mapped class.
784
+
785
+ This class represents the complete descriptor interface for any class
786
+ attribute that will have been :term:`instrumented` by the ORM
787
+ :class:`_orm.Mapper` class. Provides appropriate information to type
788
+ checkers such as pylance and mypy so that ORM-mapped attributes
789
+ are correctly typed.
790
+
791
+ The most prominent use of :class:`_orm.Mapped` is in
792
+ the :ref:`Declarative Mapping <orm_explicit_declarative_base>` form
793
+ of :class:`_orm.Mapper` configuration, where used explicitly it drives
794
+ the configuration of ORM attributes such as :func:`_orm.mapped_class`
795
+ and :func:`_orm.relationship`.
796
+
797
+ .. seealso::
798
+
799
+ :ref:`orm_explicit_declarative_base`
800
+
801
+ :ref:`orm_declarative_table`
802
+
803
+ .. tip::
804
+
805
+ The :class:`_orm.Mapped` class represents attributes that are handled
806
+ directly by the :class:`_orm.Mapper` class. It does not include other
807
+ Python descriptor classes that are provided as extensions, including
808
+ :ref:`hybrids_toplevel` and the :ref:`associationproxy_toplevel`.
809
+ While these systems still make use of ORM-specific superclasses
810
+ and structures, they are not :term:`instrumented` by the
811
+ :class:`_orm.Mapper` and instead provide their own functionality
812
+ when they are accessed on a class.
813
+
814
+ .. versionadded:: 1.4
815
+
816
+
817
+ """
818
+
819
+ __slots__ = ()
820
+
821
+ if typing.TYPE_CHECKING:
822
+
823
+ @overload
824
+ def __get__( # type: ignore[misc]
825
+ self: MappedColumn[_T_co], instance: TypedColumns, owner: Any
826
+ ) -> Column[_T_co]: ...
827
+
828
+ @overload
829
+ def __get__(
830
+ self, instance: None, owner: Any
831
+ ) -> InstrumentedAttribute[_T_co]: ...
832
+
833
+ @overload
834
+ def __get__(self, instance: object, owner: Any) -> _T_co: ...
835
+
836
+ def __get__(
837
+ self, instance: Optional[object], owner: Any
838
+ ) -> Union[InstrumentedAttribute[_T_co], Column[_T_co], _T_co]: ...
839
+
840
+ @classmethod
841
+ def _empty_constructor(cls, arg1: Any) -> Mapped[_T_co]: ...
842
+
843
+ def __set__(
844
+ self, instance: Any, value: Union[SQLCoreOperations[_T_co], _T_co]
845
+ ) -> None: ...
846
+
847
+ def __delete__(self, instance: Any) -> None: ...
848
+
849
+
850
+ class _MappedAttribute(Generic[_T_co], TypingOnly):
851
+ """Mixin for attributes which should be replaced by mapper-assigned
852
+ attributes.
853
+
854
+ """
855
+
856
+ __slots__ = ()
857
+
858
+
859
+ class _DeclarativeMapped(Mapped[_T_co], _MappedAttribute[_T_co]):
860
+ """Mixin for :class:`.MapperProperty` subclasses that allows them to
861
+ be compatible with ORM-annotated declarative mappings.
862
+
863
+ """
864
+
865
+ __slots__ = ()
866
+
867
+ # MappedSQLExpression, Relationship, Composite etc. dont actually do
868
+ # SQL expression behavior. yet there is code that compares them with
869
+ # __eq__(), __ne__(), etc. Since #8847 made Mapped even more full
870
+ # featured including ColumnOperators, we need to have those methods
871
+ # be no-ops for these objects, so return NotImplemented to fall back
872
+ # to normal comparison behavior.
873
+ def operate(self, op: OperatorType, *other: Any, **kwargs: Any) -> Any:
874
+ return NotImplemented
875
+
876
+ __sa_operate__ = operate
877
+
878
+ def reverse_operate(
879
+ self, op: OperatorType, other: Any, **kwargs: Any
880
+ ) -> Any:
881
+ return NotImplemented
882
+
883
+
884
+ class DynamicMapped(_MappedAnnotationBase[_T_co]):
885
+ """Represent the ORM mapped attribute type for a "dynamic" relationship.
886
+
887
+ The :class:`_orm.DynamicMapped` type annotation may be used in an
888
+ :ref:`Annotated Declarative Table <orm_declarative_mapped_column>` mapping
889
+ to indicate that the ``lazy="dynamic"`` loader strategy should be used
890
+ for a particular :func:`_orm.relationship`.
891
+
892
+ .. legacy:: The "dynamic" lazy loader strategy is the legacy form of what
893
+ is now the "write_only" strategy described in the section
894
+ :ref:`write_only_relationship`.
895
+
896
+ E.g.::
897
+
898
+ class User(Base):
899
+ __tablename__ = "user"
900
+ id: Mapped[int] = mapped_column(primary_key=True)
901
+ addresses: DynamicMapped[Address] = relationship(
902
+ cascade="all,delete-orphan"
903
+ )
904
+
905
+ See the section :ref:`dynamic_relationship` for background.
906
+
907
+ .. versionadded:: 2.0
908
+
909
+ .. seealso::
910
+
911
+ :ref:`dynamic_relationship` - complete background
912
+
913
+ :class:`.WriteOnlyMapped` - fully 2.0 style version
914
+
915
+ """
916
+
917
+ __slots__ = ()
918
+
919
+ if TYPE_CHECKING:
920
+
921
+ @overload
922
+ def __get__(
923
+ self, instance: None, owner: Any
924
+ ) -> InstrumentedAttribute[_T_co]: ...
925
+
926
+ @overload
927
+ def __get__(
928
+ self, instance: object, owner: Any
929
+ ) -> AppenderQuery[_T_co]: ...
930
+
931
+ def __get__(
932
+ self, instance: Optional[object], owner: Any
933
+ ) -> Union[InstrumentedAttribute[_T_co], AppenderQuery[_T_co]]: ...
934
+
935
+ def __set__(
936
+ self, instance: Any, value: typing.Collection[_T_co]
937
+ ) -> None: ...
938
+
939
+
940
+ class WriteOnlyMapped(_MappedAnnotationBase[_T_co]):
941
+ """Represent the ORM mapped attribute type for a "write only" relationship.
942
+
943
+ The :class:`_orm.WriteOnlyMapped` type annotation may be used in an
944
+ :ref:`Annotated Declarative Table <orm_declarative_mapped_column>` mapping
945
+ to indicate that the ``lazy="write_only"`` loader strategy should be used
946
+ for a particular :func:`_orm.relationship`.
947
+
948
+ E.g.::
949
+
950
+ class User(Base):
951
+ __tablename__ = "user"
952
+ id: Mapped[int] = mapped_column(primary_key=True)
953
+ addresses: WriteOnlyMapped[Address] = relationship(
954
+ cascade="all,delete-orphan"
955
+ )
956
+
957
+ See the section :ref:`write_only_relationship` for background.
958
+
959
+ .. versionadded:: 2.0
960
+
961
+ .. seealso::
962
+
963
+ :ref:`write_only_relationship` - complete background
964
+
965
+ :class:`.DynamicMapped` - includes legacy :class:`_orm.Query` support
966
+
967
+ """
968
+
969
+ __slots__ = ()
970
+
971
+ if TYPE_CHECKING:
972
+
973
+ @overload
974
+ def __get__(
975
+ self, instance: None, owner: Any
976
+ ) -> InstrumentedAttribute[_T_co]: ...
977
+
978
+ @overload
979
+ def __get__(
980
+ self, instance: object, owner: Any
981
+ ) -> WriteOnlyCollection[_T_co]: ...
982
+
983
+ def __get__(
984
+ self, instance: Optional[object], owner: Any
985
+ ) -> Union[
986
+ InstrumentedAttribute[_T_co], WriteOnlyCollection[_T_co]
987
+ ]: ...
988
+
989
+ def __set__(
990
+ self, instance: Any, value: typing.Collection[_T_co]
991
+ ) -> None: ...