MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _copy_expression

Function _copy_expression

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

Source from the content-addressed store, hash-verified

183# this should really be in sql/util.py but we'd have to
184# break an import cycle
185def _copy_expression(
186 expression: ColumnElement[Any],
187 source_table: Optional[Table],
188 target_table: Optional[Table],
189) -> ColumnElement[Any]:
190 if source_table is None or target_table is None:
191 return expression
192
193 fixed_source_table = source_table
194 fixed_target_table = target_table
195
196 def replace(
197 element: ExternallyTraversible, **kw: Any
198 ) -> Optional[ExternallyTraversible]:
199 if (
200 isinstance(element, Column)
201 and element.table is fixed_source_table
202 and element.key in fixed_source_table.c
203 ):
204 return fixed_target_table.c[element.key]
205 else:
206 return None
207
208 return cast(
209 ColumnElement[Any],
210 visitors.replacement_traverse(expression, {}, replace),
211 )
212
213
214@inspection._self_inspects

Callers 4

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

Calls 1

castFunction · 0.85

Tested by

no test coverage detected