relateby-pattern 0.7.2__cp38-abi3-win_amd64.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.
relateby/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ # Unified relateby package: relateby.pattern and relateby.gram
2
+
3
+ __all__ = ["gram", "pattern"]
@@ -0,0 +1 @@
1
+ # Native extensions: pattern_core, gram_codec
Binary file
Binary file
@@ -0,0 +1,302 @@
1
+ # relateby.gram — parse/stringify gram notation
2
+ #
3
+ # parse/stringify return/accept list[Pattern[Subject]] (native Python dataclasses).
4
+ # parse_with_header/stringify_with_header handle the optional leading header record.
5
+ # Errors surface as GramParseError with .input and .cause attributes.
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import TYPE_CHECKING
10
+
11
+ if TYPE_CHECKING:
12
+ from relateby.pattern import Pattern
13
+ from relateby.pattern._subject import Subject
14
+ from relateby.pattern._decode import RawPattern
15
+
16
+
17
+ class GramParseError(Exception):
18
+ """Raised when gram notation parsing or serialization fails.
19
+
20
+ Attributes:
21
+ input: The original gram string that caused the error (empty string
22
+ for serialization errors where there is no input text).
23
+ cause: Human-readable description of what went wrong.
24
+
25
+ Example::
26
+
27
+ from relateby.gram import parse, GramParseError
28
+
29
+ try:
30
+ parse("(unclosed")
31
+ except GramParseError as err:
32
+ print(err.input) # "(unclosed"
33
+ print(err.cause) # parse error description
34
+ """
35
+
36
+ def __init__(self, input: str, cause: str) -> None:
37
+ super().__init__(f"Gram parse error: {cause}")
38
+ self._input = input
39
+ self._cause = cause
40
+
41
+ @property
42
+ def input(self) -> str:
43
+ """The gram string that was being parsed when the error occurred."""
44
+ return self._input
45
+
46
+ @property
47
+ def cause(self) -> str:
48
+ """Human-readable description of what went wrong."""
49
+ return self._cause
50
+
51
+
52
+ def parse(input: str) -> "list[Pattern[Subject]]":
53
+ """Parse gram notation into a list of native ``Pattern[Subject]`` objects.
54
+
55
+ Each top-level element in the gram document becomes one entry in the
56
+ returned list. An empty string or whitespace-only input returns ``[]``.
57
+
58
+ Args:
59
+ input: Gram notation string, e.g. ``"(alice)-[:KNOWS]->(bob)"``.
60
+
61
+ Returns:
62
+ List of ``Pattern[Subject]`` objects, one per top-level gram element.
63
+
64
+ Raises:
65
+ GramParseError: If *input* is not valid gram notation.
66
+
67
+ Example::
68
+
69
+ from relateby.gram import parse, stringify
70
+
71
+ patterns = parse("(alice:Person)-[:KNOWS]->(bob:Person)")
72
+ assert len(patterns) == 1
73
+
74
+ gram = stringify(patterns)
75
+ # "(alice:Person)-[:KNOWS]->(bob:Person)"
76
+ """
77
+ from relateby._native import gram_codec as _gram
78
+ from relateby.pattern._decode import pattern_from_dict
79
+
80
+ try:
81
+ raw_patterns = _gram.parse(input)
82
+ return [pattern_from_dict(d) for d in raw_patterns]
83
+ except Exception as exc:
84
+ raise GramParseError(input=input, cause=str(exc)) from exc
85
+
86
+
87
+ def stringify(patterns: "list[Pattern[Subject]]") -> str:
88
+ """Serialize a list of ``Pattern[Subject]`` objects to gram notation.
89
+
90
+ Args:
91
+ patterns: List of patterns to serialize, typically the result of
92
+ :func:`parse` or :func:`parse_with_header`.
93
+
94
+ Returns:
95
+ Gram notation string representing *patterns*.
96
+
97
+ Raises:
98
+ GramParseError: If any pattern contains a value type that cannot be
99
+ represented in gram notation (e.g. ``NullVal``).
100
+
101
+ Example::
102
+
103
+ from relateby.gram import parse, stringify
104
+
105
+ patterns = parse("(a)-->(b)")
106
+ gram = stringify(patterns)
107
+ # "(a)-->(b)"
108
+
109
+ # round-trip is identity up to whitespace normalization
110
+ assert parse(gram) == parse("(a)-->(b)")
111
+ """
112
+ from relateby._native import gram_codec as _gram
113
+ from relateby.pattern._decode import pattern_to_dict
114
+
115
+ try:
116
+ raw = [pattern_to_dict(p) for p in patterns]
117
+ return _gram.stringify(raw)
118
+ except Exception as exc:
119
+ raise GramParseError(input="", cause=str(exc)) from exc
120
+
121
+
122
+ def parse_with_header(input: str) -> "tuple[dict | None, list[Pattern[Subject]]]":
123
+ """Parse gram notation, separating an optional header record from the patterns.
124
+
125
+ A *header* is a leading bare record — a ``{key: value, ...}`` block that
126
+ appears before any graph elements and has no identity or labels. It is
127
+ commonly used to store document-level metadata such as schema version or
128
+ provenance.
129
+
130
+ Args:
131
+ input: Gram notation string, optionally starting with a bare record
132
+ header, e.g. ``"{version: 1} (alice)-[:KNOWS]->(bob)"``.
133
+
134
+ Returns:
135
+ A two-tuple ``(header, patterns)`` where *header* is a plain ``dict``
136
+ if a leading bare record was present, or ``None`` otherwise, and
137
+ *patterns* is the list of ``Pattern[Subject]`` elements that follow.
138
+
139
+ Raises:
140
+ GramParseError: If *input* is not valid gram notation.
141
+
142
+ Example::
143
+
144
+ from relateby.gram import parse_with_header, stringify_with_header
145
+
146
+ # Document with a header
147
+ header, patterns = parse_with_header(
148
+ "{version: 1, source: 'export'} (alice)-[:KNOWS]->(bob)"
149
+ )
150
+ assert header == {"version": 1, "source": "export"}
151
+ assert len(patterns) == 1
152
+
153
+ # Document without a header
154
+ header2, patterns2 = parse_with_header("(alice)-[:KNOWS]->(bob)")
155
+ assert header2 is None
156
+
157
+ # Round-trip
158
+ gram = stringify_with_header(header, patterns)
159
+ header3, patterns3 = parse_with_header(gram)
160
+ assert header3 == header
161
+ """
162
+ from relateby._native import gram_codec as _gram
163
+ from relateby.pattern._decode import pattern_from_dict
164
+
165
+ try:
166
+ raw = _gram.parse_with_header(input)
167
+ header = raw.get("header")
168
+ patterns = [pattern_from_dict(d) for d in raw.get("patterns", [])]
169
+ return header, patterns
170
+ except Exception as exc:
171
+ raise GramParseError(input=input, cause=str(exc)) from exc
172
+
173
+
174
+ def stringify_with_header(
175
+ header: "dict | None",
176
+ patterns: "list[Pattern[Subject]]",
177
+ ) -> str:
178
+ """Serialize a header record and patterns to gram notation.
179
+
180
+ Produces a gram document whose first element is the header bare record
181
+ followed by the serialized patterns. Pass ``None`` as *header* to
182
+ produce output identical to :func:`stringify`.
183
+
184
+ Args:
185
+ header: A plain ``dict`` of scalar values to write as the leading
186
+ bare record, or ``None`` to omit the header entirely.
187
+ patterns: List of ``Pattern[Subject]`` objects to serialize.
188
+
189
+ Returns:
190
+ Gram notation string with the header (if provided) followed by the
191
+ patterns, separated by a newline.
192
+
193
+ Raises:
194
+ GramParseError: If any value in *header* or *patterns* cannot be
195
+ represented in gram notation (e.g. ``NullVal``).
196
+
197
+ Example::
198
+
199
+ from relateby.gram import parse, parse_with_header, stringify_with_header
200
+
201
+ patterns = parse("(alice)-[:KNOWS]->(bob)")
202
+ gram = stringify_with_header({"version": 1}, patterns)
203
+ # '{version: 1}\\n(alice)-[:KNOWS]->(bob)'
204
+
205
+ # Omitting the header is equivalent to plain stringify
206
+ gram_no_header = stringify_with_header(None, patterns)
207
+ # '(alice)-[:KNOWS]->(bob)'
208
+
209
+ # Full round-trip
210
+ header2, patterns2 = parse_with_header(gram)
211
+ assert header2 == {"version": 1}
212
+ """
213
+ from relateby._native import gram_codec as _gram
214
+ from relateby.pattern._decode import pattern_to_dict
215
+
216
+ try:
217
+ raw = {
218
+ "header": header,
219
+ "patterns": [pattern_to_dict(p) for p in patterns],
220
+ }
221
+ return _gram.stringify_with_header(raw)
222
+ except Exception as exc:
223
+ raise GramParseError(input="", cause=str(exc)) from exc
224
+
225
+
226
+ def gram_validate(input: str) -> list[str]:
227
+ """Validate gram notation and return a list of error strings.
228
+
229
+ Returns an empty list if the input is valid.
230
+ """
231
+ from relateby._native import gram_codec as _gram
232
+ try:
233
+ return _gram.gram_validate(input)
234
+ except Exception as exc:
235
+ return [str(exc)]
236
+
237
+
238
+ def round_trip(input: str) -> str:
239
+ """Parse and re-serialize gram notation (normalizes formatting)."""
240
+ from relateby._native import gram_codec as _gram
241
+ try:
242
+ return _gram.round_trip(input)
243
+ except Exception as exc:
244
+ raise GramParseError(input=input, cause=str(exc)) from exc
245
+
246
+
247
+ def parse_raw(input: str) -> "list[RawPattern]":
248
+ """Parse gram notation and return the raw JSON interchange dicts.
249
+
250
+ Returns the intermediate representation without constructing native
251
+ ``Pattern[Subject]`` objects. Use this to produce a JSON-serializable
252
+ payload for transport (e.g. server → client), then reconstruct on the
253
+ receiving side with :func:`relateby.pattern.pattern_from_dict`.
254
+
255
+ Args:
256
+ input: Gram notation string.
257
+
258
+ Returns:
259
+ List of raw interchange dicts, one per top-level gram element.
260
+
261
+ Raises:
262
+ GramParseError: If *input* is not valid gram notation.
263
+
264
+ Example::
265
+
266
+ import json
267
+ from relateby.gram import parse_raw
268
+ from relateby.pattern import pattern_from_dict, validate_payload
269
+
270
+ # Producer (has native gram support)
271
+ payload = json.dumps(parse_raw("(alice:Person)-[:KNOWS]->(bob:Person)"))
272
+
273
+ # Consumer (no native dependency needed)
274
+ data = json.loads(payload)
275
+ patterns = [pattern_from_dict(d) for d in validate_payload(data)]
276
+ """
277
+ from relateby._native import gram_codec as _gram
278
+
279
+ try:
280
+ return _gram.parse(input)
281
+ except Exception as exc:
282
+ raise GramParseError(input=input, cause=str(exc)) from exc
283
+
284
+
285
+ # Legacy aliases
286
+ parse_gram = parse
287
+ gram_stringify = stringify
288
+
289
+
290
+ __all__ = [
291
+ "GramParseError",
292
+ "parse",
293
+ "parse_raw",
294
+ "stringify",
295
+ "parse_with_header",
296
+ "stringify_with_header",
297
+ "gram_validate",
298
+ "round_trip",
299
+ # legacy aliases
300
+ "parse_gram",
301
+ "gram_stringify",
302
+ ]
@@ -0,0 +1,26 @@
1
+ from __future__ import annotations
2
+
3
+ from relateby.pattern import Pattern, RawPattern
4
+ from relateby.pattern._subject import Subject
5
+
6
+
7
+ class GramParseError(Exception):
8
+ @property
9
+ def input(self) -> str: ...
10
+ @property
11
+ def cause(self) -> str: ...
12
+
13
+
14
+ def parse(input: str) -> list[Pattern[Subject]]: ...
15
+ def parse_raw(input: str) -> list[RawPattern]: ...
16
+ def stringify(patterns: list[Pattern[Subject]]) -> str: ...
17
+ def parse_with_header(input: str) -> tuple[dict | None, list[Pattern[Subject]]]: ...
18
+ def stringify_with_header(
19
+ header: dict | None, patterns: list[Pattern[Subject]]
20
+ ) -> str: ...
21
+ def gram_validate(input: str) -> list[str]: ...
22
+ def round_trip(input: str) -> str: ...
23
+
24
+ # Legacy aliases
25
+ parse_gram = parse
26
+ gram_stringify = stringify
@@ -0,0 +1,69 @@
1
+ # relateby.pattern — native Python Pattern, Subject, and Value types
2
+ #
3
+ # These are pure Python dataclasses — no PyO3 round-trip per operation.
4
+ # Structural equality works via dataclass __eq__.
5
+
6
+ from ._pattern import Pattern, unfold
7
+ from ._subject import Subject
8
+ from ._value import (
9
+ Value,
10
+ StringVal,
11
+ IntVal,
12
+ FloatVal,
13
+ BoolVal,
14
+ NullVal,
15
+ SymbolVal,
16
+ TaggedStringVal,
17
+ ArrayVal,
18
+ MapVal,
19
+ RangeVal,
20
+ MeasurementVal,
21
+ value_from_dict,
22
+ value_to_dict,
23
+ )
24
+ from ._decode import RawPattern, RawSubject, pattern_from_dict, pattern_to_dict, validate_payload
25
+ from ._standard_graph import StandardGraph
26
+ from ._graph_transforms import (
27
+ GraphQuery,
28
+ Substitution,
29
+ map_graph,
30
+ map_all_graph,
31
+ filter_graph,
32
+ fold_graph,
33
+ map_with_context,
34
+ para_graph,
35
+ )
36
+
37
+ __all__ = [
38
+ "Pattern",
39
+ "Subject",
40
+ "Value",
41
+ "StringVal",
42
+ "IntVal",
43
+ "FloatVal",
44
+ "BoolVal",
45
+ "NullVal",
46
+ "SymbolVal",
47
+ "TaggedStringVal",
48
+ "ArrayVal",
49
+ "MapVal",
50
+ "RangeVal",
51
+ "MeasurementVal",
52
+ "value_from_dict",
53
+ "value_to_dict",
54
+ "RawPattern",
55
+ "RawSubject",
56
+ "pattern_from_dict",
57
+ "pattern_to_dict",
58
+ "validate_payload",
59
+ "StandardGraph",
60
+ "unfold",
61
+ "GraphQuery",
62
+ "Substitution",
63
+ "map_graph",
64
+ "map_all_graph",
65
+ "filter_graph",
66
+ "fold_graph",
67
+ "map_with_context",
68
+ "para_graph",
69
+ ]
@@ -0,0 +1,229 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Callable, Generic, Iterator, Optional, TypedDict, TypeVar, Union, overload
4
+
5
+ V = TypeVar("V")
6
+ U = TypeVar("U")
7
+ R = TypeVar("R")
8
+ A = TypeVar("A")
9
+
10
+
11
+ class StringVal:
12
+ value: str
13
+ def __init__(self, value: str) -> None: ...
14
+
15
+
16
+ class IntVal:
17
+ value: int
18
+ def __init__(self, value: int) -> None: ...
19
+
20
+
21
+ class FloatVal:
22
+ value: float
23
+ def __init__(self, value: float) -> None: ...
24
+
25
+
26
+ class BoolVal:
27
+ value: bool
28
+ def __init__(self, value: bool) -> None: ...
29
+
30
+
31
+ class NullVal:
32
+ def __init__(self) -> None: ...
33
+
34
+
35
+ class SymbolVal:
36
+ value: str
37
+ def __init__(self, value: str) -> None: ...
38
+
39
+
40
+ class TaggedStringVal:
41
+ tag: str
42
+ content: str
43
+ def __init__(self, tag: str, content: str) -> None: ...
44
+
45
+
46
+ class ArrayVal:
47
+ items: list["Value"]
48
+ def __init__(self, items: list["Value"]) -> None: ...
49
+
50
+
51
+ class MapVal:
52
+ entries: dict[str, "Value"]
53
+ def __init__(self, entries: dict[str, "Value"]) -> None: ...
54
+
55
+
56
+ class RangeVal:
57
+ lower: Optional[float]
58
+ upper: Optional[float]
59
+ def __init__(self, lower: Optional[float] = ..., upper: Optional[float] = ...) -> None: ...
60
+
61
+
62
+ class MeasurementVal:
63
+ unit: str
64
+ value: float
65
+ def __init__(self, unit: str, value: float) -> None: ...
66
+
67
+
68
+ Value = Union[
69
+ StringVal,
70
+ IntVal,
71
+ FloatVal,
72
+ BoolVal,
73
+ NullVal,
74
+ SymbolVal,
75
+ TaggedStringVal,
76
+ ArrayVal,
77
+ MapVal,
78
+ RangeVal,
79
+ MeasurementVal,
80
+ ]
81
+
82
+
83
+ class Subject:
84
+ identity: str
85
+ labels: set[str]
86
+ properties: dict[str, Value]
87
+ def __init__(
88
+ self,
89
+ identity: str,
90
+ labels: Optional[set[str]] = ...,
91
+ properties: Optional[dict[str, Value]] = ...,
92
+ ) -> None: ...
93
+ @classmethod
94
+ def from_id(cls, identity: str) -> "Subject": ...
95
+ def with_label(self, label: str) -> "Subject": ...
96
+ def with_property(self, name: str, value: Value) -> "Subject": ...
97
+
98
+
99
+ class Pattern(Generic[V]):
100
+ value: V
101
+ elements: list["Pattern[V]"]
102
+ def __init__(self, value: V, elements: Optional[list["Pattern[V]"]] = ...) -> None: ...
103
+ @classmethod
104
+ def point(cls, value: V) -> "Pattern[V]": ...
105
+ @classmethod
106
+ def of(cls, value: V) -> "Pattern[V]": ...
107
+ @classmethod
108
+ def pattern(cls, value: V, elements: list["Pattern[V]"]) -> "Pattern[V]": ...
109
+ @classmethod
110
+ def from_list(cls, value: V, values: list[V]) -> "Pattern[V]": ...
111
+ @classmethod
112
+ def unfold(cls, expand: Callable[[A], tuple[V, list[A]]], seed: A) -> "Pattern[V]": ...
113
+ @property
114
+ def is_atomic(self) -> bool: ...
115
+ @property
116
+ def length(self) -> int: ...
117
+ @property
118
+ def size(self) -> int: ...
119
+ @property
120
+ def depth(self) -> int: ...
121
+ def map(self, fn: Callable[[V], U]) -> "Pattern[U]": ...
122
+ def fold(self, init: R, fn: Callable[[R, V], R]) -> R: ...
123
+ def filter(self, predicate: Callable[["Pattern[V]"], bool]) -> list["Pattern[V]"]: ...
124
+ def find_first(self, predicate: Callable[[V], bool]) -> Optional[V]: ...
125
+ def extend(self, fn: Callable[["Pattern[V]"], U]) -> "Pattern[U]": ...
126
+ def extract(self) -> V: ...
127
+ def duplicate(self) -> "Pattern[Pattern[V]]": ...
128
+ def values(self) -> list[V]: ...
129
+ def any_value(self, predicate: Callable[[V], bool]) -> bool: ...
130
+ def all_values(self, predicate: Callable[[V], bool]) -> bool: ...
131
+ def matches(self, other: "Pattern[V]") -> bool: ...
132
+ def contains(self, needle: "Pattern[V]") -> bool: ...
133
+ def para(self, f: Callable[["Pattern[V]", list[R]], R]) -> R: ...
134
+ def combine(self, other: "Pattern[V]", combine_values: Callable[[V, V], V]) -> "Pattern[V]": ...
135
+ def depth_at(self) -> "Pattern[int]": ...
136
+ def size_at(self) -> "Pattern[int]": ...
137
+ def indices_at(self) -> "Pattern[list[int]]": ...
138
+ def __iter__(self) -> Iterator["Pattern[V]"]: ...
139
+
140
+
141
+ def value_from_dict(d: object) -> Value: ...
142
+ def value_to_dict(v: Value) -> object: ...
143
+
144
+ class RawSubject(TypedDict):
145
+ identity: str
146
+ labels: list[str]
147
+ properties: dict[str, Any]
148
+
149
+ class RawPattern(TypedDict):
150
+ subject: RawSubject
151
+ elements: list[RawPattern]
152
+
153
+ def validate_payload(raw: object) -> list[RawPattern]: ...
154
+ def pattern_from_dict(d: RawPattern) -> Pattern[Subject]: ...
155
+ def pattern_to_dict(p: Pattern[Subject]) -> RawPattern: ...
156
+ def unfold(expand: Callable[[A], tuple[V, list[A]]], seed: A) -> Pattern[V]: ...
157
+
158
+ Substitution = Union[str, tuple[str, Pattern[Subject]]]
159
+
160
+ class GraphQuery:
161
+ def nodes(self) -> list[Pattern[Subject]]: ...
162
+ def relationships(self) -> list[Pattern[Subject]]: ...
163
+ def source(self, rel: Pattern[Subject]) -> Optional[Pattern[Subject]]: ...
164
+ def target(self, rel: Pattern[Subject]) -> Optional[Pattern[Subject]]: ...
165
+ def incident_rels(self, node: Pattern[Subject]) -> list[Pattern[Subject]]: ...
166
+ def degree(self, node: Pattern[Subject]) -> int: ...
167
+ def node_by_id(self, identity: str) -> Optional[Pattern[Subject]]: ...
168
+ def relationship_by_id(self, identity: str) -> Optional[Pattern[Subject]]: ...
169
+
170
+ def map_graph(
171
+ graph: StandardGraph,
172
+ mappers: dict[str, Callable[[Pattern[Subject]], Pattern[Subject]]],
173
+ ) -> StandardGraph: ...
174
+ def map_all_graph(
175
+ graph: StandardGraph,
176
+ f: Callable[[Pattern[Subject]], Pattern[Subject]],
177
+ ) -> StandardGraph: ...
178
+ def filter_graph(
179
+ graph: StandardGraph,
180
+ predicate: Callable[[str, Pattern[Subject]], bool],
181
+ substitution: Substitution,
182
+ ) -> StandardGraph: ...
183
+ def fold_graph(
184
+ graph: StandardGraph,
185
+ f: Callable[[str, Pattern[Subject]], R],
186
+ empty: R,
187
+ combine: Callable[[R, R], R],
188
+ ) -> R: ...
189
+ def map_with_context(
190
+ graph: StandardGraph,
191
+ f: Callable[[GraphQuery, Pattern[Subject]], Pattern[Subject]],
192
+ ) -> StandardGraph: ...
193
+ def para_graph(
194
+ graph: StandardGraph,
195
+ f: Callable[[GraphQuery, Pattern[Subject], dict[str, R]], R],
196
+ ) -> dict[str, R]: ...
197
+
198
+
199
+ class StandardGraph:
200
+ def __init__(self) -> None: ...
201
+ @classmethod
202
+ def from_patterns(cls, patterns: list[Pattern[Subject]]) -> "StandardGraph": ...
203
+ @classmethod
204
+ def from_gram(cls, input: str) -> "StandardGraph": ...
205
+ @property
206
+ def node_count(self) -> int: ...
207
+ @property
208
+ def relationship_count(self) -> int: ...
209
+ @property
210
+ def annotation_count(self) -> int: ...
211
+ @property
212
+ def walk_count(self) -> int: ...
213
+ @property
214
+ def is_empty(self) -> bool: ...
215
+ @property
216
+ def has_conflicts(self) -> bool: ...
217
+ def nodes(self) -> Iterator[tuple[str, Pattern[Subject]]]: ...
218
+ def relationships(self) -> Iterator[tuple[str, dict[str, Any]]]: ...
219
+ def annotations(self) -> Iterator[tuple[str, Pattern[Subject]]]: ...
220
+ def walks(self) -> Iterator[tuple[str, Pattern[Subject]]]: ...
221
+ def other(self) -> list[Pattern[Subject]]: ...
222
+ def node(self, id: str) -> Optional[Pattern[Subject]]: ...
223
+ def relationship(self, id: str) -> Optional[dict[str, Any]]: ...
224
+ def annotation(self, id: str) -> Optional[Pattern[Subject]]: ...
225
+ def walk(self, id: str) -> Optional[Pattern[Subject]]: ...
226
+ def source(self, rel_id: str) -> Optional[Pattern[Subject]]: ...
227
+ def target(self, rel_id: str) -> Optional[Pattern[Subject]]: ...
228
+ def neighbors(self, node_id: str) -> list[Pattern[Subject]]: ...
229
+ def degree(self, node_id: str) -> int: ...