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