Skip to content

mode.utils.types.graphs

Type classes for mode.utils.graphs.

DependencyGraphT

Bases: Generic[_T], Mapping[_T, _T]

Type class for dependency graphs.

Source code in mode/utils/types/graphs.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
class DependencyGraphT(Generic[_T], Mapping[_T, _T]):
    """Type class for dependency graphs."""

    adjacent: MutableMapping[_T, _T]

    @abc.abstractmethod
    def __init__(
        self,
        it: Optional[Iterable[_T]] = None,
        formatter: Optional[GraphFormatterT[_T]] = None,
    ) -> None: ...

    @abc.abstractmethod
    def add_arc(self, obj: _T) -> None: ...

    @abc.abstractmethod
    def add_edge(self, A: _T, B: _T) -> None: ...

    @abc.abstractmethod
    def connect(self, graph: "DependencyGraphT") -> None: ...

    @abc.abstractmethod
    def topsort(self) -> Sequence: ...

    @abc.abstractmethod
    def valency_of(self, obj: _T) -> int: ...

    @abc.abstractmethod
    def update(self, it: Iterable) -> None: ...

    @abc.abstractmethod
    def edges(self) -> Iterable: ...

    @abc.abstractmethod
    def to_dot(
        self, fh: IO, *, formatter: GraphFormatterT[_T] = None
    ) -> None: ...

GraphFormatterT

Bases: Generic[_T]

Type class for graph formatters.

Source code in mode/utils/types/graphs.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class GraphFormatterT(Generic[_T]):
    """Type class for graph formatters."""

    scheme: Mapping[str, Any]
    edge_scheme: Mapping[str, Any]
    node_scheme: Mapping[str, Any]
    term_scheme: Mapping[str, Any]
    graph_scheme: Mapping[str, Any]

    @abc.abstractmethod
    def __init__(
        self,
        root: Any = None,
        type: Optional[str] = None,
        id: Optional[str] = None,
        indent: int = 0,
        inw: str = " " * 4,
        **scheme: Any,
    ) -> None: ...

    @abc.abstractmethod
    def attr(self, name: str, value: Any) -> str: ...

    @abc.abstractmethod
    def attrs(
        self, d: Optional[Mapping] = None, scheme: Optional[Mapping] = None
    ) -> str: ...

    @abc.abstractmethod
    def head(self, **attrs: Any) -> str: ...

    @abc.abstractmethod
    def tail(self) -> str: ...

    @abc.abstractmethod
    def label(self, obj: _T) -> str: ...

    @abc.abstractmethod
    def node(self, obj: _T, **attrs: Any) -> str: ...

    @abc.abstractmethod
    def terminal_node(self, obj: _T, **attrs: Any) -> str: ...

    @abc.abstractmethod
    def edge(self, a: _T, b: _T, **attrs: Any) -> str: ...

    @abc.abstractmethod
    def FMT(self, fmt: str, *args: Any, **kwargs: Any) -> str: ...

    @abc.abstractmethod
    def draw_edge(
        self,
        a: _T,
        b: _T,
        scheme: Optional[Mapping] = None,
        attrs: Optional[Mapping] = None,
    ) -> str: ...

    @abc.abstractmethod
    def draw_node(
        self,
        obj: _T,
        scheme: Optional[Mapping] = None,
        attrs: Optional[Mapping] = None,
    ) -> str: ...