|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | | -from copy import deepcopy |
6 | 5 | from dataclasses import asdict, dataclass, field, is_dataclass |
7 | 6 | from enum import Enum, IntEnum |
8 | 7 | from os import getenv |
@@ -203,6 +202,16 @@ def destroy(self) -> None: |
203 | 202 | self.state.deleted = False |
204 | 203 | ctx_src.remove(self) |
205 | 204 |
|
| 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 | + |
206 | 215 | def unsync(self: TANCH) -> TANCH: |
207 | 216 | """Return unsynced copy of anchor.""" |
208 | 217 | unsynced = object.__new__(self.__class__) |
@@ -312,11 +321,7 @@ def __getstate__(self) -> dict[str, object]: |
312 | 321 | """Serialize Anchor.""" |
313 | 322 | state: dict[str, object] = {"name": self.name, "id": self.id} |
314 | 323 |
|
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(): |
320 | 325 | state.update( |
321 | 326 | { |
322 | 327 | "root": self.root, |
|
0 commit comments