Add some missing networkx annotations (#11181)

This commit is contained in:
Neil Girdhar
2023-12-19 06:21:47 -05:00
committed by GitHub
parent 2dfa9544ed
commit ba7bd9f98a
2 changed files with 17 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
from _typeshed import Incomplete
from collections.abc import Callable, Collection, Hashable, Iterable, Iterator, Mapping, MutableMapping
from typing import ClassVar, TypeVar, overload
from typing import Any, ClassVar, TypeVar, overload
from typing_extensions import Self, TypeAlias
import numpy
@@ -9,16 +9,19 @@ from networkx.classes.digraph import DiGraph
from networkx.classes.reportviews import DiDegreeView, NodeView, OutEdgeView
_Node = TypeVar("_Node", bound=Hashable)
_NodeWithData: TypeAlias = tuple[_Node, dict[str, Any]]
_NodePlus: TypeAlias = _Node | _NodeWithData[_Node]
_Edge: TypeAlias = tuple[_Node, _Node]
_EdgePlus: TypeAlias = _Edge[_Node] | tuple[_Node, _Node, dict[str, Incomplete]]
_MapFactory: TypeAlias = Callable[[], MutableMapping[str, Incomplete]]
_EdgeWithData: TypeAlias = tuple[_Node, _Node, dict[str, Any]]
_EdgePlus: TypeAlias = _Edge[_Node] | _EdgeWithData[_Node]
_MapFactory: TypeAlias = Callable[[], MutableMapping[str, Any]]
_NBunch: TypeAlias = _Node | Iterable[_Node] | None
_Data: TypeAlias = (
Graph[_Node]
| dict[_Node, dict[_Node, dict[str, Incomplete]]]
| dict[_Node, dict[_Node, dict[str, Any]]]
| dict[_Node, Iterable[_Node]]
| Iterable[_EdgePlus[_Node]]
| numpy.ndarray[_Node, Incomplete]
| numpy.ndarray[_Node, Any]
# | scipy.sparse.base.spmatrix
)
@@ -42,9 +45,7 @@ class Graph(Collection[_Node]):
def __contains__(self, n: object) -> bool: ...
def __len__(self) -> int: ...
def add_node(self, node_for_adding: _Node, **attr) -> None: ...
def add_nodes_from(
self, nodes_for_adding: Iterable[_Node | tuple[_Node, dict[str, Incomplete]]], **attr: Incomplete
) -> None: ...
def add_nodes_from(self, nodes_for_adding: Iterable[_NodePlus[_Node]], **attr: Incomplete) -> None: ...
def remove_node(self, n: _Node) -> None: ...
def remove_nodes_from(self, nodes: Iterable[_Node]) -> None: ...
nodes: NodeView[_Node]

View File

@@ -1,4 +1,7 @@
from _typeshed import Incomplete
from collections.abc import Callable, Iterable
from networkx.classes.graph import Graph, _Data, _Node
__all__ = [
"to_networkx_graph",
@@ -10,9 +13,11 @@ __all__ = [
"to_edgelist",
]
def to_networkx_graph(data, create_using=None, multigraph_input=False): ...
def to_dict_of_lists(G, nodelist=None) -> dict[Incomplete, Incomplete]: ...
def from_dict_of_lists(d, create_using=None): ...
def to_networkx_graph(
data: _Data[_Node], create_using: Graph[_Node] | Callable[[], Graph[_Node]] | None = None, multigraph_input: bool = False
) -> Graph[_Node]: ...
def to_dict_of_lists(G: Graph[_Node], nodelist: None | Iterable[_Node] = None) -> dict[_Node, list[_Node]]: ...
def from_dict_of_lists(d: dict[_Node, Iterable[_Node]], create_using: Incomplete | None = None) -> Incomplete: ...
def to_dict_of_dicts(G, nodelist=None, edge_data=None) -> dict[Incomplete, Incomplete]: ...
def from_dict_of_dicts(d, create_using=None, multigraph_input=False): ...
def to_edgelist(G, nodelist=None): ...