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

Method _clone

lib/sqlalchemy/sql/elements.py:417–444  ·  view source on GitHub ↗

Create a shallow copy of this ClauseElement. This method may be used by a generative API. Its also used as part of the "deep" copy afforded by a traversal that combines the _copy_internals() method.

(self, **kw: Any)

Source from the content-addressed store, hash-verified

415 return dialect.statement_compiler(dialect, self) # type: ignore
416
417 def _clone(self, **kw: Any) -> Self:
418 """Create a shallow copy of this ClauseElement.
419
420 This method may be used by a generative API. Its also used as
421 part of the "deep" copy afforded by a traversal that combines
422 the _copy_internals() method.
423
424 """
425
426 skip = self._memoized_keys
427 c = self.__class__.__new__(self.__class__)
428
429 if skip:
430 # ensure this iteration remains atomic
431 c.__dict__ = {
432 k: v for k, v in self.__dict__.copy().items() if k not in skip
433 }
434 else:
435 c.__dict__ = self.__dict__.copy()
436
437 # this is a marker that helps to "equate" clauses to each other
438 # when a Select returns its list of FROM clauses. the cloning
439 # process leaves around a lot of remnants of the previous clause
440 # typically in the form of column expressions still attached to the
441 # old table.
442 cc = self._is_clone_of
443 c._is_clone_of = cc if cc is not None else self
444 return c
445
446 def _negate_in_binary(self, negated_op, original_op):
447 """a hook to allow the right side of a binary expression to respond

Callers

nothing calls this directly

Calls 3

__new__Method · 0.45
itemsMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected