topkit 0.2.0a3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- TopKit/__init__.py +82 -0
- TopKit/access.py +357 -0
- TopKit/contracts.py +360 -0
- TopKit/declarations.py +1010 -0
- TopKit/errors.py +138 -0
- TopKit/fields.py +165 -0
- TopKit/geometry.py +120 -0
- TopKit/lifecycle.py +220 -0
- TopKit/overlay.py +791 -0
- TopKit/queries.py +90 -0
- TopKit/state.py +862 -0
- TopKit/tags.py +251 -0
- TopKit/transactions.py +474 -0
- topkit-0.2.0a3.dist-info/METADATA +136 -0
- topkit-0.2.0a3.dist-info/RECORD +18 -0
- topkit-0.2.0a3.dist-info/WHEEL +5 -0
- topkit-0.2.0a3.dist-info/licenses/LICENSE +202 -0
- topkit-0.2.0a3.dist-info/top_level.txt +1 -0
TopKit/queries.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Queries on an Agent: procedural spellings that never touch the Agent's
|
|
2
|
+
own attribute namespace."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from .geometry import _form_of
|
|
9
|
+
from .geometry import _leaves
|
|
10
|
+
from .state import _name_of
|
|
11
|
+
from .state import _state_of
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def Form(
|
|
15
|
+
tag: type,
|
|
16
|
+
) -> tuple[type, ...]:
|
|
17
|
+
"""The Base-first closure of a Tag, ending with the Tag itself."""
|
|
18
|
+
|
|
19
|
+
return _form_of(tag)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def Apply(
|
|
23
|
+
target: object,
|
|
24
|
+
*tags: type,
|
|
25
|
+
**inputs: Any,
|
|
26
|
+
) -> object:
|
|
27
|
+
"""Apply several Tags in order; return the same Target."""
|
|
28
|
+
|
|
29
|
+
for tag in tags:
|
|
30
|
+
tag(
|
|
31
|
+
target,
|
|
32
|
+
**inputs,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
return target
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def Keyword(
|
|
39
|
+
agent: object,
|
|
40
|
+
*words: type | str,
|
|
41
|
+
) -> bool:
|
|
42
|
+
"""True when the Agent carries every given keyword: the name, or the
|
|
43
|
+
class, of an active Flag Tag. Works on any object, tagged or not."""
|
|
44
|
+
|
|
45
|
+
from .access import _keyword
|
|
46
|
+
|
|
47
|
+
return all(
|
|
48
|
+
_keyword(agent, word)
|
|
49
|
+
for word in words
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def Tags(
|
|
54
|
+
agent: object,
|
|
55
|
+
) -> tuple[type, ...]:
|
|
56
|
+
"""The active leaf Tags, in application order."""
|
|
57
|
+
|
|
58
|
+
state = _state_of(agent)
|
|
59
|
+
|
|
60
|
+
if state is None:
|
|
61
|
+
return ()
|
|
62
|
+
|
|
63
|
+
return _leaves(state.active)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def Outline(
|
|
67
|
+
agent: object,
|
|
68
|
+
indent: str = " ",
|
|
69
|
+
) -> str:
|
|
70
|
+
"""A readable picture of the Agent's Geometry: host, then each leaf's
|
|
71
|
+
Form from Base to Shape."""
|
|
72
|
+
|
|
73
|
+
state = _state_of(agent)
|
|
74
|
+
host = _name_of(agent)
|
|
75
|
+
lines = [host]
|
|
76
|
+
|
|
77
|
+
if state is None:
|
|
78
|
+
return host
|
|
79
|
+
|
|
80
|
+
active = set(state.active)
|
|
81
|
+
|
|
82
|
+
for leaf in _leaves(state.active):
|
|
83
|
+
depth = 1
|
|
84
|
+
|
|
85
|
+
for tag in _form_of(leaf):
|
|
86
|
+
if tag in active:
|
|
87
|
+
lines.append(f"{indent * depth}{tag.__name__}")
|
|
88
|
+
depth += 1
|
|
89
|
+
|
|
90
|
+
return "\n".join(lines)
|