MCPcopy Create free account
hub / github.com/BUPT-GAMMA/MASFactory / __deepcopy__

Method __deepcopy__

masfactory/core/node_template.py:268–283  ·  view source on GitHub ↗

Deep-copy via MASFactory clone semantics instead of Python's generic object walk. This ensures nested NodeTemplate declarations still respect `Shared(...)`, `Factory(...)`, and `__node_template_scope__` when an outer template clones them as part of its prototype config.

(self, memo: dict[int, Any])

Source from the content-addressed store, hash-verified

266 self.prototype_config = default_kwargs
267
268 def __deepcopy__(self, memo: dict[int, Any]) -> "NodeTemplate[T]":
269 """Deep-copy via MASFactory clone semantics instead of Python's generic object walk.
270
271 This ensures nested NodeTemplate declarations still respect `Shared(...)`,
272 `Factory(...)`, and `__node_template_scope__` when an outer template clones
273 them as part of its prototype config.
274 """
275 obj_id = id(self)
276 if obj_id in memo:
277 return memo[obj_id]
278
279 cloned = object.__new__(type(self))
280 memo[obj_id] = cloned
281 cloned.node_cls = self.node_cls
282 cloned.prototype_config = _safe_clone(self.prototype_config, memo)
283 return cloned
284
285 def render_config(self, **override_kwargs) -> dict[str, Any]:
286 final_config = _safe_clone(self.prototype_config)

Callers

nothing calls this directly

Calls 2

_safe_cloneFunction · 0.85
__new__Method · 0.80

Tested by

no test coverage detected