graphinate.typing.Edges.__call__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
"""
2
Typing Module
3
4
Attributes:
5
  Node (Node): Node Type
6
  Edge (Edge): Edge Type
7
  Element (Element): Element Type
8
  Extractor (Extractor): Source of data for an Element
9
  UniverseNode (UniverseNode): The Universe Node Type. All Node Types are the implicit children of UniverseNodeType.
10
"""
11
12
from collections.abc import Callable, Iterable
13
from typing import Any, NamedTuple, NewType, Protocol, TypeAlias, TypeVar, Union
14
15
import networkx as nx
16
import networkx_mermaid as nxm
17
import strawberry
18
19
NodeTuple: TypeAlias = tuple[str, Any]
20
EdgeTuple: TypeAlias = tuple[str, str, Any]
21
22
IdentifierStr = NewType('IdentifierStr', str)
23
IdentifierStr.__doc__ = 'A string that is a valid Python identifier (i.e., `isidentifier()` is True).'
24
25
NodeTypeAbsoluteId = NewType('NodeTypeAbsoluteId', tuple[str, str])
26
NodeTypeAbsoluteId.__doc__ = 'A unique identifier for a node type.'
27
28
29
class UniverseNode:
30
    """The UniverseNode Type. All Node Types are the implicit children of the Universe Node Type."""
31
32
33
# A node in a graph.
34
Node = Union[type[NamedTuple], NodeTuple]  # noqa: UP007
35
36
# An edge in a graph.
37
Edge = Union[type[NamedTuple], EdgeTuple]  # noqa: UP007
38
39
# An element in a graph.
40
Element = Union[Node, Edge]  # noqa: UP007
41
42
# A source of data for an element.
43
Extractor = Union[str, Callable[[Any], str]]  # noqa: UP007
44
45
T = TypeVar('T')
46
47
48
class Items(Protocol):
49
    """Protocol for callable objects that return an iterable of items."""
50
51
    def __call__(self, **kwargs: Any) -> Iterable[T]:  # pragma: no cover
52
        ...
53
54
55
class Nodes(Protocol):
56
    """Protocol for callable objects that return an iterable of nodes."""
57
58
    def __call__(self, **kwargs: Any) -> Iterable[Node]:  # pragma: no cover
59
        ...
60
61
62
class Edges(Protocol):
63
    """Protocol for callable objects that return an iterable of edges."""
64
65
    def __call__(self, **kwargs: Any) -> Iterable[Edge]:  # pragma: no cover
66
        ...
67
68
69
class Predicate(Protocol):
70
    """Protocol for callable objects that evaluate a condition."""
71
72
    def __call__(self, **kwargs: Any) -> bool:  # pragma: no cover
73
        ...
74
75
76
class Supplier(Protocol):
77
    """Protocol for callable objects that supply a value."""
78
79
    def __call__(self) -> Any:  # pragma: no cover
80
        ...
81
82
83
GraphRepresentation = Union[dict, nx.Graph, strawberry.Schema, nxm.typing.MermaidDiagram, str]  # noqa: UP007
84