|
| 1 | +from _typeshed import StrPath, SupportsWrite |
| 2 | +from collections.abc import Collection |
| 3 | +from typing_extensions import TypeAlias, TypeVar |
| 4 | + |
| 5 | +from networkx.classes.graph import Graph, _Node |
| 6 | + |
1 | 7 | __all__ = ["to_latex_raw", "to_latex", "write_latex"]
|
2 | 8 |
|
| 9 | +# runtime requires a dict but it doesn't mutate it, we use a bounded typevar as |
| 10 | +# a values type to make type checkers treat the dict covariantely |
| 11 | +_PosT = TypeVar("_PosT", bound=Collection[float] | str) |
| 12 | +_Pos: TypeAlias = str | dict[_Node, _PosT] |
| 13 | + |
3 | 14 | def to_latex_raw(
|
4 |
| - G, |
5 |
| - pos: str = "pos", |
| 15 | + G: Graph[_Node], |
| 16 | + pos: _Pos[_Node, _PosT] = "pos", |
6 | 17 | tikz_options: str = "",
|
7 | 18 | default_node_options: str = "",
|
8 |
| - node_options: str = "node_options", |
9 |
| - node_label: str = "label", |
| 19 | + node_options: str | dict[_Node, str] = "node_options", |
| 20 | + node_label: str | dict[_Node, str] = "label", |
10 | 21 | default_edge_options: str = "",
|
11 |
| - edge_options: str = "edge_options", |
12 |
| - edge_label: str = "label", |
13 |
| - edge_label_options: str = "edge_label_options", |
14 |
| -): ... |
| 22 | + edge_options: str | dict[tuple[_Node, _Node], str] = "edge_options", |
| 23 | + edge_label: str | dict[tuple[_Node, _Node], str] = "label", |
| 24 | + edge_label_options: str | dict[tuple[_Node, _Node], str] = "edge_label_options", |
| 25 | +) -> str: ... |
15 | 26 | def to_latex(
|
16 |
| - Gbunch, |
17 |
| - pos: str = "pos", |
| 27 | + Gbunch: Graph[_Node] | Collection[Graph[_Node]], |
| 28 | + pos: _Pos[_Node, _PosT] | Collection[_Pos[_Node, _PosT]] = "pos", |
| 29 | + tikz_options: str = "", |
| 30 | + default_node_options: str = "", |
| 31 | + node_options: str | dict[_Node, str] = "node_options", |
| 32 | + node_label: str | dict[_Node, str] = "node_label", |
| 33 | + default_edge_options: str = "", |
| 34 | + edge_options: str | dict[tuple[_Node, _Node], str] = "edge_options", |
| 35 | + edge_label: str | dict[tuple[_Node, _Node], str] = "edge_label", |
| 36 | + edge_label_options: str | dict[tuple[_Node, _Node], str] = "edge_label_options", |
| 37 | + caption: str = "", |
| 38 | + latex_label: str = "", |
| 39 | + sub_captions: Collection[str] | None = None, |
| 40 | + sub_labels: Collection[str] | None = None, |
| 41 | + n_rows: int = 1, |
| 42 | + as_document: bool = True, |
| 43 | + document_wrapper: str = ..., |
| 44 | + figure_wrapper: str = ..., |
| 45 | + subfigure_wrapper: str = ..., |
| 46 | +) -> str: ... |
| 47 | +def write_latex( |
| 48 | + Gbunch: Graph[_Node] | Collection[Graph[_Node]], |
| 49 | + path: StrPath | SupportsWrite[str], |
| 50 | + *, |
| 51 | + # **options passed to `to_latex` |
| 52 | + pos: _Pos[_Node, _PosT] | Collection[_Pos[_Node, _PosT]] = "pos", |
18 | 53 | tikz_options: str = "",
|
19 | 54 | default_node_options: str = "",
|
20 |
| - node_options: str = "node_options", |
21 |
| - node_label: str = "node_label", |
| 55 | + node_options: str | dict[_Node, str] = "node_options", |
| 56 | + node_label: str | dict[_Node, str] = "node_label", |
22 | 57 | default_edge_options: str = "",
|
23 |
| - edge_options: str = "edge_options", |
24 |
| - edge_label: str = "edge_label", |
25 |
| - edge_label_options: str = "edge_label_options", |
| 58 | + edge_options: str | dict[tuple[_Node, _Node], str] = "edge_options", |
| 59 | + edge_label: str | dict[tuple[_Node, _Node], str] = "edge_label", |
| 60 | + edge_label_options: str | dict[tuple[_Node, _Node], str] = "edge_label_options", |
26 | 61 | caption: str = "",
|
27 | 62 | latex_label: str = "",
|
28 |
| - sub_captions=None, |
29 |
| - sub_labels=None, |
| 63 | + sub_captions: Collection[str] | None = None, |
| 64 | + sub_labels: Collection[str] | None = None, |
30 | 65 | n_rows: int = 1,
|
31 | 66 | as_document: bool = True,
|
32 | 67 | document_wrapper: str = ...,
|
33 | 68 | figure_wrapper: str = ...,
|
34 | 69 | subfigure_wrapper: str = ...,
|
35 |
| -): ... |
36 |
| -def write_latex(Gbunch, path, **options) -> None: ... |
| 70 | +) -> None: ... |
0 commit comments