Skip to content

Commit

Permalink
Add some missing networkx annotations (#11181)
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilGirdhar authored Dec 19, 2023
1 parent 2dfa954 commit ba7bd9f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
17 changes: 9 additions & 8 deletions stubs/networkx/networkx/classes/graph.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
)

Expand All @@ -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]
Expand Down
11 changes: 8 additions & 3 deletions stubs/networkx/networkx/convert.pyi
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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): ...
Expand Down

0 comments on commit ba7bd9f

Please sign in to comment.