Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit d75fc1d

Browse files
committed
[MINOR]: Use shallow cloning instead of copy/deepcopy
1 parent 03dbf72 commit d75fc1d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

jaclang/runtimelib/architype.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
from copy import deepcopy
65
from dataclasses import asdict, dataclass, field, is_dataclass
76
from enum import Enum, IntEnum
87
from os import getenv
@@ -203,6 +202,16 @@ def destroy(self) -> None:
203202
self.state.deleted = False
204203
ctx_src.remove(self)
205204

205+
def unlinked_architype(self) -> Architype | None:
206+
"""Unlink architype."""
207+
# this is to avoid using copy/deepcopy as it can be overriden by architypes in language level
208+
if self.architype:
209+
cloned = object.__new__(self.architype.__class__)
210+
cloned.__dict__.update(self.architype.__dict__)
211+
cloned.__dict__.pop("__jac__", None)
212+
return cloned
213+
return None
214+
206215
def unsync(self: TANCH) -> TANCH:
207216
"""Return unsynced copy of anchor."""
208217
unsynced = object.__new__(self.__class__)
@@ -312,11 +321,7 @@ def __getstate__(self) -> dict[str, object]:
312321
"""Serialize Anchor."""
313322
state: dict[str, object] = {"name": self.name, "id": self.id}
314323

315-
if self.architype:
316-
# clone architype excluding __jac__
317-
architype = deepcopy(self.architype, memo={id(self): self})
318-
architype.__dict__.pop("__jac__")
319-
324+
if architype := self.unlinked_architype():
320325
state.update(
321326
{
322327
"root": self.root,

0 commit comments

Comments
 (0)