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

Commit 30232ce

Browse files
committed
[REFACTOR]: Rename ObjectAnchor to Anchor
1 parent 7dc9c71 commit 30232ce

File tree

5 files changed

+39
-41
lines changed

5 files changed

+39
-41
lines changed

jaclang/cli/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from jaclang.compiler.passes.main.pyast_load_pass import PyastBuildPass
1919
from jaclang.compiler.passes.main.schedules import py_code_gen_typed
2020
from jaclang.compiler.passes.tool.schedules import format_pass
21-
from jaclang.core.constructs import NodeAnchor, ObjectAnchor
21+
from jaclang.core.constructs import Anchor, NodeAnchor
2222
from jaclang.plugin.builtin import dotgen
2323
from jaclang.plugin.feature import JacCmd as Cmd
2424
from jaclang.plugin.feature import JacFeature as Jac
@@ -141,7 +141,7 @@ def get_object(id: str, session: str = "") -> dict[str, object]:
141141
if id == "root":
142142
super_root = jctx.super_root
143143
response = super_root.serialize()
144-
elif (anchor := ObjectAnchor.ref(id)) and anchor.sync():
144+
elif (anchor := Anchor.ref(id)) and anchor.sync():
145145
response = anchor.serialize()
146146

147147
jctx.close()

jaclang/core/architype.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def deserialize(cls, data: dict[str, Any]) -> Permission:
140140

141141

142142
@dataclass(eq=False)
143-
class ObjectAnchor:
143+
class Anchor:
144144
"""Object Anchor."""
145145

146146
type: ObjectType = ObjectType.generic
@@ -160,10 +160,10 @@ def ref_id(self) -> str:
160160
return f"{self.type.value}:{self.name}:{self.id}"
161161

162162
@staticmethod
163-
def ref(ref_id: str) -> Optional[ObjectAnchor]:
163+
def ref(ref_id: str) -> Optional[Anchor]:
164164
"""Return ObjectAnchor instance if ."""
165165
if matched := GENERIC_ID_REGEX.search(ref_id):
166-
cls: type = ObjectAnchor
166+
cls: type = Anchor
167167
match ObjectType(matched.group(1)):
168168
case ObjectType.node:
169169
cls = NodeAnchor
@@ -209,19 +209,19 @@ def allocate(self) -> None:
209209
self.root = jctx.root.id
210210
jctx.datasource.set(self, True)
211211

212-
def has_read_access(self, to: ObjectAnchor) -> bool:
212+
def has_read_access(self, to: Anchor) -> bool:
213213
"""Read Access Validation."""
214214
return self.access_level(to) > -1
215215

216-
def has_connect_access(self, to: ObjectAnchor) -> bool:
216+
def has_connect_access(self, to: Anchor) -> bool:
217217
"""Write Access Validation."""
218218
return self.access_level(to) > 0
219219

220-
def has_write_access(self, to: ObjectAnchor) -> bool:
220+
def has_write_access(self, to: Anchor) -> bool:
221221
"""Write Access Validation."""
222222
return self.access_level(to) > 1
223223

224-
def access_level(self, to: ObjectAnchor) -> int:
224+
def access_level(self, to: Anchor) -> int:
225225
"""Access validation."""
226226
from .context import ExecutionContext
227227

@@ -301,7 +301,7 @@ def __hash__(self) -> int:
301301

302302
def __eq__(self, other: object) -> bool:
303303
"""Override equal implementation."""
304-
if isinstance(other, ObjectAnchor):
304+
if isinstance(other, Anchor):
305305
return (
306306
self.type == other.type
307307
and self.name == other.name
@@ -316,7 +316,7 @@ def __eq__(self, other: object) -> bool:
316316

317317

318318
@dataclass(eq=False)
319-
class NodeAnchor(ObjectAnchor):
319+
class NodeAnchor(Anchor):
320320
"""Node Anchor."""
321321

322322
type: ObjectType = ObjectType.node
@@ -480,7 +480,7 @@ def serialize(self) -> dict[str, object]:
480480

481481

482482
@dataclass(eq=False)
483-
class EdgeAnchor(ObjectAnchor):
483+
class EdgeAnchor(Anchor):
484484
"""Edge Anchor."""
485485

486486
type: ObjectType = ObjectType.edge
@@ -585,14 +585,14 @@ def serialize(self) -> dict[str, object]:
585585

586586

587587
@dataclass(eq=False)
588-
class WalkerAnchor(ObjectAnchor):
588+
class WalkerAnchor(Anchor):
589589
"""Walker Anchor."""
590590

591591
type: ObjectType = ObjectType.walker
592592
architype: Optional[WalkerArchitype] = None
593-
path: list[ObjectAnchor] = field(default_factory=list)
594-
next: list[ObjectAnchor] = field(default_factory=list)
595-
ignores: list[ObjectAnchor] = field(default_factory=list)
593+
path: list[Anchor] = field(default_factory=list)
594+
next: list[Anchor] = field(default_factory=list)
595+
ignores: list[Anchor] = field(default_factory=list)
596596
disengaged: bool = False
597597
persistent: bool = False # Disabled initially but can be adjusted
598598

@@ -667,7 +667,7 @@ def disengage_now(self) -> None:
667667
"""Disengage walker from traversal."""
668668
self.disengaged = True
669669

670-
def spawn_call(self, nd: ObjectAnchor) -> WalkerArchitype:
670+
def spawn_call(self, nd: Anchor) -> WalkerArchitype:
671671
"""Invoke data spatial call."""
672672
if walker := self.sync():
673673
self.path = []
@@ -718,16 +718,16 @@ class Architype:
718718
_jac_exit_funcs_: list[DSFunc]
719719
_jac_classes_: dict[str, type[Architype]]
720720

721-
def __init__(self, __jac__: Optional[ObjectAnchor] = None) -> None:
721+
def __init__(self, __jac__: Optional[Anchor] = None) -> None:
722722
"""Create default architype."""
723-
self.__jac__ = __jac__ or ObjectAnchor(architype=self)
723+
self.__jac__ = __jac__ or Anchor(architype=self)
724724
self.__jac__.allocate()
725725

726726
def __eq__(self, other: object) -> bool:
727727
"""Override equal implementation."""
728728
if isinstance(other, Architype):
729729
return super().__eq__(other)
730-
elif isinstance(other, ObjectAnchor):
730+
elif isinstance(other, Anchor):
731731
return self.__jac__ == other
732732

733733
return False

jaclang/core/constructs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55

66
from .architype import (
7+
Anchor,
78
Architype,
89
DSFunc,
910
EdgeAnchor,
1011
EdgeArchitype,
1112
GenericEdge,
1213
NodeAnchor,
1314
NodeArchitype,
14-
ObjectAnchor,
1515
Root,
1616
WalkerAnchor,
1717
WalkerArchitype,
@@ -21,7 +21,7 @@
2121
from .test import JacTestCheck, JacTestResult, JacTextTestRunner
2222

2323
__all__ = [
24-
"ObjectAnchor",
24+
"Anchor",
2525
"NodeAnchor",
2626
"EdgeAnchor",
2727
"WalkerAnchor",

jaclang/core/memory.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
from uuid import UUID
88

99
from .architype import (
10+
Anchor,
1011
Architype,
1112
EdgeAnchor,
1213
EdgeArchitype,
1314
MANUAL_SAVE,
1415
NodeAnchor,
1516
NodeArchitype,
16-
ObjectAnchor,
1717
ObjectType,
1818
Permission,
1919
WalkerAnchor,
@@ -27,7 +27,7 @@
2727
class Memory:
2828
"""Generic Memory Handler."""
2929

30-
__mem__: dict[str, ObjectAnchor] = field(default_factory=dict)
30+
__mem__: dict[str, Anchor] = field(default_factory=dict)
3131
__gc__: set[str] = field(default_factory=set)
3232

3333
def close(self) -> None:
@@ -40,8 +40,8 @@ def __del__(self) -> None:
4040
self.close()
4141

4242
def find(
43-
self, ids: IDS, filter: Optional[Callable[[ObjectAnchor], ObjectAnchor]] = None
44-
) -> Generator[ObjectAnchor, None, None]:
43+
self, ids: IDS, filter: Optional[Callable[[Anchor], Anchor]] = None
44+
) -> Generator[Anchor, None, None]:
4545
"""Find anchors from memory by ids with filter."""
4646
if not isinstance(ids, list):
4747
ids = [ids]
@@ -55,12 +55,12 @@ def find(
5555
def find_one(
5656
self,
5757
ids: IDS,
58-
filter: Optional[Callable[[ObjectAnchor], ObjectAnchor]] = None,
59-
) -> Optional[ObjectAnchor]:
58+
filter: Optional[Callable[[Anchor], Anchor]] = None,
59+
) -> Optional[Anchor]:
6060
"""Find one anchor from memory by ids with filter."""
6161
return next(self.find(ids, filter), None)
6262

63-
def set(self, data: Union[ObjectAnchor, list[ObjectAnchor]]) -> None:
63+
def set(self, data: Union[Anchor, list[Anchor]]) -> None:
6464
"""Save anchor/s to memory."""
6565
if isinstance(data, list):
6666
for d in data:
@@ -69,7 +69,7 @@ def set(self, data: Union[ObjectAnchor, list[ObjectAnchor]]) -> None:
6969
elif str(data.id) not in self.__gc__:
7070
self.__mem__[str(data.id)] = data
7171

72-
def remove(self, data: Union[ObjectAnchor, list[ObjectAnchor]]) -> None:
72+
def remove(self, data: Union[Anchor, list[Anchor]]) -> None:
7373
"""Remove anchor/s from memory."""
7474
if isinstance(data, list):
7575
for d in data:
@@ -106,8 +106,8 @@ def close(self) -> None:
106106
super().close()
107107

108108
def find(
109-
self, ids: IDS, filter: Optional[Callable[[ObjectAnchor], ObjectAnchor]] = None
110-
) -> Generator[ObjectAnchor, None, None]:
109+
self, ids: IDS, filter: Optional[Callable[[Anchor], Anchor]] = None
110+
) -> Generator[Anchor, None, None]:
111111
"""Find anchors from datasource by ids with filter."""
112112
if not isinstance(ids, list):
113113
ids = [ids]
@@ -128,9 +128,7 @@ def find(
128128
else:
129129
yield from super().find(ids, filter)
130130

131-
def set(
132-
self, data: Union[ObjectAnchor, list[ObjectAnchor]], mem_only: bool = False
133-
) -> None:
131+
def set(self, data: Union[Anchor, list[Anchor]], mem_only: bool = False) -> None:
134132
"""Save anchor/s to datasource."""
135133
super().set(data)
136134

@@ -146,7 +144,7 @@ def set(
146144
if d.current_access_level > 1:
147145
self.__shelf__[_id]["architype"] = json["architype"]
148146

149-
def remove(self, data: Union[ObjectAnchor, list[ObjectAnchor]]) -> None:
147+
def remove(self, data: Union[Anchor, list[Anchor]]) -> None:
150148
"""Remove anchor/s from datasource."""
151149
super().remove(data)
152150
if isinstance(self.__shelf__, Shelf) and MANUAL_SAVE:
@@ -156,7 +154,7 @@ def remove(self, data: Union[ObjectAnchor, list[ObjectAnchor]]) -> None:
156154
else:
157155
self.__shelf__.pop(str(data.id), None)
158156

159-
def get(self, anchor: dict[str, Any]) -> ObjectAnchor:
157+
def get(self, anchor: dict[str, Any]) -> Anchor:
160158
"""Get Anchor Instance."""
161159
name = cast(str, anchor.get("name"))
162160
architype = anchor.pop("architype")
@@ -191,6 +189,6 @@ def get(self, anchor: dict[str, Any]) -> ObjectAnchor:
191189
wanch.architype = WalkerArchitype.get(name)(__jac__=wanch, **architype)
192190
return wanch
193191
case _:
194-
oanch = ObjectAnchor(access=access, **anchor)
192+
oanch = Anchor(access=access, **anchor)
195193
oanch.architype = Architype(__jac__=oanch)
196194
return oanch

jaclang/plugin/default.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from jaclang.compiler.constant import EdgeDir, T, colors
1717
from jaclang.compiler.semtable import SemInfo, SemRegistry, SemScope
1818
from jaclang.core.constructs import (
19+
Anchor,
1920
Architype,
2021
DSFunc,
2122
EdgeAnchor,
@@ -24,7 +25,6 @@
2425
JacTestCheck,
2526
NodeAnchor,
2627
NodeArchitype,
27-
ObjectAnchor,
2828
Root,
2929
WalkerAnchor,
3030
WalkerArchitype,
@@ -43,7 +43,7 @@
4343
"GenericEdge",
4444
"JacTestCheck",
4545
"NodeAnchor",
46-
"ObjectAnchor",
46+
"Anchor",
4747
"WalkerAnchor",
4848
"NodeArchitype",
4949
"EdgeArchitype",
@@ -112,7 +112,7 @@ def make_architype(
112112
def new_init(
113113
self: Architype,
114114
*args: object,
115-
__jac__: Optional[ObjectAnchor] = None,
115+
__jac__: Optional[Anchor] = None,
116116
**kwargs: object,
117117
) -> None:
118118
arch_base.__init__(self, __jac__)

0 commit comments

Comments
 (0)