MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _copy_expression

Function _copy_expression

lib/sqlalchemy/sql/schema.py:196–222  ·  view source on GitHub ↗
(
    expression: ColumnElement[Any],
    source_table: Optional[Table],
    target_table: Optional[Table],
)

Source from the content-addressed store, hash-verified

194# this should really be in sql/util.py but we'd have to
195# break an import cycle
196def _copy_expression(
197 expression: ColumnElement[Any],
198 source_table: Optional[Table],
199 target_table: Optional[Table],
200) -> ColumnElement[Any]:
201 if source_table is None or target_table is None:
202 return expression
203
204 fixed_source_table = source_table
205 fixed_target_table = target_table
206
207 def replace(
208 element: ExternallyTraversible, **kw: Any
209 ) -> Optional[ExternallyTraversible]:
210 if (
211 isinstance(element, Column)
212 and element.table is fixed_source_table
213 and element.key in fixed_source_table.c
214 ):
215 return fixed_target_table.c[element.key]
216 else:
217 return None
218
219 return cast(
220 ColumnElement[Any],
221 visitors.replacement_traverse(expression, {}, replace),
222 )
223
224
225@inspection._self_inspects

Callers 4

to_metadataMethod · 0.85
_copyMethod · 0.85
_copyMethod · 0.85
_copyMethod · 0.85

Calls 1

castFunction · 0.70

Tested by

no test coverage detected