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

Function clone

lib/sqlalchemy/sql/annotation.py:433–474  ·  view source on GitHub ↗
(elem: SupportsAnnotations, **kw: Any)

Source from the content-addressed store, hash-verified

431 cloned_ids: Dict[int, SupportsAnnotations] = {}
432
433 def clone(elem: SupportsAnnotations, **kw: Any) -> SupportsAnnotations:
434 # ind_cols_on_fromclause means make sure an AnnotatedFromClause
435 # has its own .c collection independent of that which its proxying.
436 # this is used specifically by orm.LoaderCriteriaOption to break
437 # a reference cycle that it's otherwise prone to building,
438 # see test_relationship_criteria->
439 # test_loader_criteria_subquery_w_same_entity. logic here was
440 # changed for #8796 and made explicit; previously it occurred
441 # by accident
442
443 kw["detect_subquery_cols"] = detect_subquery_cols
444 id_ = id(elem)
445
446 if id_ in cloned_ids:
447 return cloned_ids[id_]
448
449 if (
450 exclude
451 and hasattr(elem, "proxy_set")
452 and elem.proxy_set.intersection(exclude)
453 ):
454 newelem = elem._clone(clone=clone, **kw)
455 elif annotations != elem._annotations:
456 if detect_subquery_cols and elem._is_immutable:
457 to_annotate = elem._clone(clone=clone, **kw)
458 else:
459 to_annotate = elem
460 if annotate_callable:
461 newelem = annotate_callable(to_annotate, annotations)
462 else:
463 newelem = _safe_annotate(to_annotate, annotations)
464 else:
465 newelem = elem
466
467 newelem._copy_internals(
468 clone=clone,
469 ind_cols_on_fromclause=ind_cols_on_fromclause,
470 _annotations_traversal=True,
471 )
472
473 cloned_ids[id_] = newelem
474 return newelem
475
476 if element is not None:
477 element = cast(_SA, clone(element))

Callers 2

_deep_annotateFunction · 0.70
_deep_deannotateFunction · 0.70

Calls 5

_safe_annotateFunction · 0.85
intersectionMethod · 0.45
_cloneMethod · 0.45
_copy_internalsMethod · 0.45
_deannotateMethod · 0.45

Tested by

no test coverage detected