MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _copy_internals

Method _copy_internals

lib/sqlalchemy/sql/selectable.py:1401–1438  ·  view source on GitHub ↗
(
        self, clone: _CloneCallableType = _clone, **kw: Any
    )

Source from the content-addressed store, hash-verified

1399 )
1400
1401 def _copy_internals(
1402 self, clone: _CloneCallableType = _clone, **kw: Any
1403 ) -> None:
1404 # see Select._copy_internals() for similar concept
1405
1406 # here we pre-clone "left" and "right" so that we can
1407 # determine the new FROM clauses
1408 all_the_froms = set(
1409 itertools.chain(
1410 _from_objects(self.left),
1411 _from_objects(self.right),
1412 )
1413 )
1414
1415 # run the clone on those. these will be placed in the
1416 # cache used by the clone function
1417 new_froms = {f: clone(f, **kw) for f in all_the_froms}
1418
1419 # set up a special replace function that will replace for
1420 # ColumnClause with parent table referring to those
1421 # replaced FromClause objects
1422 def replace(
1423 obj: Union[BinaryExpression[Any], ColumnClause[Any]],
1424 **kw: Any,
1425 ) -> Optional[KeyedColumnElement[Any]]:
1426 if isinstance(obj, ColumnClause) and obj.table in new_froms:
1427 newelem = new_froms[obj.table].corresponding_column(obj)
1428 return newelem
1429 return None
1430
1431 kw["replace"] = replace
1432
1433 # run normal _copy_internals. the clones for
1434 # left and right will come from the clone function's
1435 # cache
1436 super()._copy_internals(clone=clone, **kw)
1437
1438 self._reset_memoizations()
1439
1440 def _refresh_for_new_column(self, column: ColumnElement[Any]) -> None:
1441 super()._refresh_for_new_column(column)

Callers 3

_copy_internalsMethod · 0.45
_copy_internalsMethod · 0.45
_copy_internalsMethod · 0.45

Calls 4

_from_objectsFunction · 0.85
_reset_memoizationsMethod · 0.80
cloneFunction · 0.70
chainMethod · 0.45

Tested by

no test coverage detected