Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions stubs/networkx/networkx/algorithms/clique.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from _typeshed import Incomplete
from collections.abc import Generator, Iterable, Iterator
from typing import overload

from networkx.classes.graph import Graph, _Node
from networkx.classes.graph import Graph, _EdgeData, _Node, _NodeData
from networkx.utils.backends import _dispatchable

__all__ = [
Expand All @@ -23,10 +23,15 @@ def find_cliques(G: Graph[_Node], nodes: Iterable[Incomplete] | None = None) ->
@_dispatchable
def find_cliques_recursive(G: Graph[_Node], nodes: Iterable[Incomplete] | None = None) -> Iterator[list[_Node]]: ...
@_dispatchable
def make_max_clique_graph(G: Graph[_Node], create_using: Graph[_Node] | None = None) -> Graph[_Node]: ...
def make_max_clique_graph(
G: Graph[_Node], create_using: Graph[_Node, _NodeData, _EdgeData] | None = None
) -> Graph[_Node, _NodeData, _EdgeData]: ...
@_dispatchable
def make_clique_bipartite(
G: Graph[_Node], fpos: bool | None = None, create_using: Graph[_Node] | None = None, name=None
G: Graph[_Node, _NodeData, _EdgeData],
fpos: bool | None = None,
create_using: Graph[_Node, _NodeData, _EdgeData] | None = None,
name=None,
) -> Graph[_Node]: ...
@overload
def node_clique_number(
Expand Down
12 changes: 7 additions & 5 deletions stubs/networkx/networkx/algorithms/dag.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from _typeshed import Incomplete
from collections.abc import Callable, Generator, Iterable

from networkx.classes.digraph import DiGraph
from networkx.classes.graph import Graph, _Node
from networkx.classes.graph import Graph, _EdgeData, _Node, _NodeData
from networkx.utils.backends import _dispatchable

__all__ = [
Expand Down Expand Up @@ -40,11 +40,13 @@ def all_topological_sorts(G: DiGraph[_Node]) -> Generator[list[_Node]]: ...
@_dispatchable
def is_aperiodic(G: DiGraph[_Node]) -> bool: ...
@_dispatchable
def transitive_closure(G: Graph[_Node], reflexive=False) -> Graph[_Node]: ...
def transitive_closure(G: Graph[_Node, _NodeData, _EdgeData], reflexive=False) -> Graph[_Node, _NodeData, _EdgeData]: ...
@_dispatchable
def transitive_closure_dag(G: DiGraph[_Node], topo_order: Iterable[Incomplete] | None = None) -> DiGraph[_Node]: ...
def transitive_closure_dag(
G: DiGraph[_Node, _NodeData, _EdgeData], topo_order: Iterable[Incomplete] | None = None
) -> DiGraph[_Node, _NodeData, _EdgeData]: ...
@_dispatchable
def transitive_reduction(G: DiGraph[_Node]) -> DiGraph[_Node]: ...
def transitive_reduction(G: DiGraph[_Node, _NodeData, _EdgeData]) -> DiGraph[_Node, _NodeData, _EdgeData]: ...
@_dispatchable
def antichains(G: DiGraph[_Node], topo_order: Iterable[Incomplete] | None = None) -> Generator[list[_Node]]: ...
@_dispatchable
Expand All @@ -57,4 +59,4 @@ def dag_longest_path(
@_dispatchable
def dag_longest_path_length(G: DiGraph[_Node], weight: str | None = "weight", default_weight: int | None = 1) -> int: ...
@_dispatchable
def dag_to_branching(G: DiGraph[_Node]) -> DiGraph[_Node]: ...
def dag_to_branching(G: DiGraph[_Node, _NodeData, _EdgeData]) -> DiGraph[_Node, _NodeData, _EdgeData]: ...
6 changes: 3 additions & 3 deletions stubs/networkx/networkx/algorithms/planarity.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from decimal import Decimal
from typing import NoReturn

from networkx.classes.digraph import DiGraph
from networkx.classes.graph import Graph, _EdgePlus, _Node
from networkx.classes.graph import Graph, _EdgeData, _EdgePlus, _Node, _NodeData
from networkx.utils.backends import _dispatchable

__all__ = ["check_planarity", "is_planar", "PlanarEmbedding"]
Expand All @@ -14,9 +14,9 @@ def is_planar(G: Graph[_Node]) -> bool: ...
@_dispatchable
def check_planarity(G: Graph[_Node], counterexample: bool = False): ...
@_dispatchable
def get_counterexample(G: Graph[_Node]) -> Graph[_Node]: ...
def get_counterexample(G: Graph[_Node, _NodeData, _EdgeData]) -> Graph[_Node, _NodeData, _EdgeData]: ...
@_dispatchable
def get_counterexample_recursive(G: Graph[_Node]) -> Graph[_Node]: ...
def get_counterexample_recursive(G: Graph[_Node, _NodeData, _EdgeData]) -> Graph[_Node, _NodeData, _EdgeData]: ...

class Interval:
low: Incomplete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from collections.abc import Callable, Generator, Iterable, Iterator
from typing import Final, Literal

from networkx.classes.digraph import DiGraph
from networkx.classes.graph import Graph, _Node
from networkx.classes.graph import Graph, _EdgeData, _Node, _NodeData
from networkx.utils.backends import _dispatchable

__all__ = [
Expand Down Expand Up @@ -30,12 +30,12 @@ def bfs_edges(
) -> Generator[tuple[_Node, _Node]]: ...
@_dispatchable
def bfs_tree(
G: Graph[_Node],
G: Graph[_Node, _NodeData, _EdgeData],
source: _Node,
reverse: bool | None = False,
depth_limit: int | None = None,
sort_neighbors: Callable[[Iterator[_Node]], Iterable[_Node]] | None = None,
) -> DiGraph[_Node]: ...
) -> DiGraph[_Node, _NodeData, _EdgeData]: ...
@_dispatchable
def bfs_predecessors(
G: Graph[_Node],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from collections.abc import Callable, Generator, Iterable, Iterator
from typing import Literal

from networkx.classes.digraph import DiGraph
from networkx.classes.graph import Graph, _Node
from networkx.classes.graph import Graph, _EdgeData, _Node, _NodeData
from networkx.utils.backends import _dispatchable

__all__ = [
Expand All @@ -25,12 +25,12 @@ def dfs_edges(
) -> Generator[tuple[_Node, _Node]]: ...
@_dispatchable
def dfs_tree(
G: Graph[_Node],
G: Graph[_Node, _NodeData, _EdgeData],
source: _Node | None = None,
depth_limit: int | None = None,
*,
sort_neighbors: Callable[[Iterator[_Node]], Iterable[_Node]] | None = None,
) -> DiGraph[_Node]: ...
) -> DiGraph[_Node, _NodeData, _EdgeData]: ...
@_dispatchable
def dfs_predecessors(
G: Graph[_Node],
Expand Down
18 changes: 9 additions & 9 deletions stubs/networkx/networkx/classes/digraph.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from typing import Any
from typing_extensions import Self

from networkx.classes.coreviews import AdjacencyView
from networkx.classes.graph import Graph, _Node
from networkx.classes.graph import Graph, _EdgeData, _Node, _NodeData
from networkx.classes.reportviews import (
DiDegreeView,
InDegreeView,
Expand All @@ -21,7 +21,7 @@ __all__ = ["DiGraph"]
# NOTE: Graph subclasses relationships are so complex
# we're only overriding methods that differ in signature from the base classes
# to use inheritance to our advantage and reduce complexity
class DiGraph(Graph[_Node]):
class DiGraph(Graph[_Node, _NodeData, _EdgeData]):
@cached_property
def succ(self) -> AdjacencyView[_Node, _Node, dict[str, Any]]: ...
@cached_property
Expand All @@ -34,19 +34,19 @@ class DiGraph(Graph[_Node]):

def predecessors(self, n: _Node) -> Iterator[_Node]: ...
@cached_property
def edges(self) -> OutEdgeView[_Node]: ...
def edges(self) -> OutEdgeView[_Node, _NodeData, _EdgeData]: ...
@cached_property
def out_edges(self) -> OutEdgeView[_Node]: ...
def out_edges(self) -> OutEdgeView[_Node, _NodeData, _EdgeData]: ...
@cached_property
# Including subtypes' possible return types for LSP
def in_edges(self) -> InEdgeView[_Node] | InMultiEdgeView[_Node]: ...
def in_edges(self) -> InEdgeView[_Node, _NodeData, _EdgeData] | InMultiEdgeView[_Node, _NodeData, _EdgeData]: ...
@cached_property
def degree(self) -> DiDegreeView[_Node]: ...
def degree(self) -> DiDegreeView[_Node, _NodeData, _EdgeData]: ...
@cached_property
# Including subtypes' possible return types for LSP
def in_degree(self) -> InDegreeView[_Node] | InMultiDegreeView[_Node]: ...
def in_degree(self) -> InDegreeView[_Node, _NodeData, _EdgeData] | InMultiDegreeView[_Node, _NodeData, _EdgeData]: ...
@cached_property
# Including subtypes' possible return types for LSP
def out_degree(self) -> OutDegreeView[_Node] | OutMultiDegreeView[_Node]: ...
def to_undirected(self, reciprocal: bool = False, as_view: bool = False) -> Graph[_Node]: ... # type: ignore[override] # Has an additional `reciprocal` keyword argument
def out_degree(self) -> OutDegreeView[_Node, _NodeData, _EdgeData] | OutMultiDegreeView[_Node, _NodeData, _EdgeData]: ...
def to_undirected(self, reciprocal: bool = False, as_view: bool = False) -> Graph[_Node, _NodeData, _EdgeData]: ... # type: ignore[override] # Has an additional `reciprocal` keyword argument
def reverse(self, copy: bool = True) -> Self: ...
12 changes: 6 additions & 6 deletions stubs/networkx/networkx/classes/function.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from typing import Literal, TypeVar, overload
from networkx import _dispatchable
from networkx.algorithms.planarity import PlanarEmbedding
from networkx.classes.digraph import DiGraph
from networkx.classes.graph import Graph, _NBunch, _Node
from networkx.classes.graph import Graph, _EdgeData, _NBunch, _Node, _NodeData
from networkx.classes.multigraph import MultiGraph

__all__ = [
Expand Down Expand Up @@ -73,7 +73,7 @@ def add_star(G_to_add_to, nodes_for_star, **attr) -> None: ...
def add_path(G_to_add_to, nodes_for_path, **attr) -> None: ...
def add_cycle(G_to_add_to, nodes_for_cycle, **attr) -> None: ...
def subgraph(G: Graph[_Node], nbunch): ...
def induced_subgraph(G: Graph[_Node], nbunch: _NBunch[_Node]) -> Graph[_Node]: ...
def induced_subgraph(G: Graph[_Node, _NodeData, _EdgeData], nbunch: _NBunch[_Node]) -> Graph[_Node, _NodeData, _EdgeData]: ...
def edge_subgraph(G: Graph[_Node], edges): ...
def restricted_view(G: Graph[_Node], nodes, edges): ...
def to_directed(graph): ...
Expand Down Expand Up @@ -146,8 +146,8 @@ def selfloop_edges(
) -> Generator[tuple[_Node, _Node]]: ...
@overload
def selfloop_edges(
G: Graph[_Node], data: Literal[True], keys: Literal[False] = False, default=None
) -> Generator[tuple[_Node, _Node, dict[str, Incomplete]]]: ...
G: Graph[_Node, _NodeData, _EdgeData], data: Literal[True], keys: Literal[False] = False, default=None
) -> Generator[tuple[_Node, _Node, _EdgeData]]: ...
@overload
def selfloop_edges(
G: Graph[_Node], data: str, keys: Literal[False] = False, default: _U | None = None
Expand All @@ -162,8 +162,8 @@ def selfloop_edges(
) -> Generator[tuple[_Node, _Node, int]]: ...
@overload
def selfloop_edges(
G: Graph[_Node], data: Literal[True], keys: Literal[True], default=None
) -> Generator[tuple[_Node, _Node, int, dict[str, Incomplete]]]: ...
G: Graph[_Node, _NodeData, _EdgeData], data: Literal[True], keys: Literal[True], default=None
) -> Generator[tuple[_Node, _Node, int, _EdgeData]]: ...
@overload
def selfloop_edges(
G: Graph[_Node], data: str, keys: Literal[True], default: _U | None = None
Expand Down
63 changes: 37 additions & 26 deletions stubs/networkx/networkx/classes/graph.pyi
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
from collections.abc import Callable, Collection, Hashable, Iterable, Iterator, MutableMapping
from collections.abc import Callable, Collection, Hashable, Iterable, Iterator, Mapping, MutableMapping
from decimal import Decimal
from functools import cached_property
from typing import Any, ClassVar, TypeVar, overload
from typing import Any, ClassVar, Generic, TypeVar, overload
from typing_extensions import Self, TypeAlias

import numpy
from networkx.classes.coreviews import AdjacencyView, AtlasView
from networkx.classes.digraph import DiGraph
from networkx.classes.reportviews import DegreeView, DiDegreeView, EdgeView, NodeView, OutEdgeView

_DataBound: TypeAlias = Mapping[str, Any]

_Node = TypeVar("_Node", bound=Hashable)
_NodeWithData: TypeAlias = tuple[_Node, dict[str, Any]]
_NodePlus: TypeAlias = _Node | _NodeWithData[_Node]
_NodeData = TypeVar("_NodeData", bound=_DataBound, default=dict[str, Any])
_EdgeData = TypeVar("_EdgeData", bound=_DataBound, default=dict[str, Any])

_NodeWithData: TypeAlias = tuple[_Node, _NodeData]
_NodePlus: TypeAlias = _Node | _NodeWithData[_Node, _NodeData]
_Edge: TypeAlias = tuple[_Node, _Node]
_EdgeWithData: TypeAlias = tuple[_Node, _Node, dict[str, Any]]
_EdgePlus: TypeAlias = _Edge[_Node] | _EdgeWithData[_Node]
_EdgeWithData: TypeAlias = tuple[_Node, _Node, _EdgeData]
_EdgePlus: TypeAlias = _Edge[_Node] | _EdgeWithData[_Node, _EdgeData]
_MapFactory: TypeAlias = Callable[[], MutableMapping[str, Any]]
_NBunch: TypeAlias = _Node | Iterable[_Node] | None
_Data: TypeAlias = (
Graph[_Node]
| dict[_Node, dict[_Node, dict[str, Any]]]
Graph[_Node, _NodeData, _EdgeData]
| dict[_Node, dict[_Node, _NodeData]]
| dict[_Node, Iterable[_Node]]
| Iterable[_EdgePlus[_Node]]
| Iterable[_EdgePlus[_Node, _EdgeData]]
| numpy.ndarray[Any, Any]
# | scipy.sparse.base.spmatrix
)

__all__ = ["Graph"]

class Graph(Collection[_Node]):
class Graph(Collection[_Node], Generic[_Node, _NodeData, _EdgeData]):
__networkx_backend__: ClassVar[str]
node_dict_factory: ClassVar[_MapFactory]
node_attr_dict_factory: ClassVar[_MapFactory]
Expand All @@ -40,14 +45,16 @@ class Graph(Collection[_Node]):
graph: dict[str, Any]
__networkx_cache__: dict[str, Any]

def to_directed_class(self) -> type[DiGraph[_Node]]: ...
def to_undirected_class(self) -> type[Graph[_Node]]: ...
def to_directed_class(self) -> type[DiGraph[_Node, _NodeData, _EdgeData]]: ...
def to_undirected_class(self) -> type[Graph[_Node, _NodeData, _EdgeData]]: ...
# @_dispatchable adds `backend` argument, but this decorated is unsupported constructor type here
# and __init__() ignores this argument
def __new__(cls, *args, backend=None, **kwargs) -> Self: ...
def __init__(self, incoming_graph_data: _Data[_Node] | None = None, **attr: Any) -> None: ... # attr: key=value pairs
def __init__(
self, incoming_graph_data: _Data[_Node, _NodeData, _EdgeData] | None = None, **attr: Any
) -> None: ... # attr: key=value pairs
@cached_property
def adj(self) -> AdjacencyView[_Node, _Node, dict[str, Any]]: ...
def adj(self) -> AdjacencyView[_Node, _Node, _EdgeData]: ...
# This object is a read-only dict-like structure
@property
def name(self) -> str: ...
Expand All @@ -58,49 +65,53 @@ class Graph(Collection[_Node]):
def __len__(self) -> int: ...
def __getitem__(self, n: _Node) -> AtlasView[_Node, str, Any]: ...
def add_node(self, node_for_adding: _Node, **attr: Any) -> None: ... # attr: Set or change node attributes using key=value
def add_nodes_from(self, nodes_for_adding: Iterable[_NodePlus[_Node]], **attr: Any) -> None: ... # attr: key=value pairs
def add_nodes_from(
self, nodes_for_adding: Iterable[_NodePlus[_Node, _NodeData]], **attr: Any
) -> None: ... # attr: key=value pairs
def remove_node(self, n: _Node) -> None: ...
def remove_nodes_from(self, nodes: Iterable[_Node]) -> None: ...
@cached_property
def nodes(self) -> NodeView[_Node]: ...
def nodes(self) -> NodeView[_Node, _NodeData, _EdgeData]: ...
def number_of_nodes(self) -> int: ...
def order(self) -> int: ...
def has_node(self, n: _Node) -> bool: ...
# Including subtypes' possible return types for LSP
def add_edge(self, u_of_edge: _Node, v_of_edge: _Node, **attr: Any) -> Hashable | None: ...
# attr: Edge data (or labels or objects) can be assigned using keyword arguments
def add_edges_from(self, ebunch_to_add: Iterable[_EdgePlus[_Node]], **attr: Any) -> None: ...
def add_edges_from(self, ebunch_to_add: Iterable[_EdgePlus[_Node, _EdgeData]], **attr: Any) -> None: ...
# attr: Edge data (or labels or objects) can be assigned using keyword arguments
def add_weighted_edges_from(
self, ebunch_to_add: Iterable[tuple[_Node, _Node, float | Decimal | None]], weight: str = "weight", **attr: Any
) -> None: ...
# attr: Edge attributes to add/update for all edges.
def remove_edge(self, u: _Node, v: _Node) -> None: ...
def remove_edges_from(self, ebunch: Iterable[_EdgePlus[_Node]]) -> None: ...
def remove_edges_from(self, ebunch: Iterable[_EdgePlus[_Node, _EdgeData]]) -> None: ...
@overload
def update(self, edges: Graph[_Node], nodes: None = None) -> None: ...
def update(self, edges: Graph[_Node, _NodeData, _EdgeData], nodes: None = None) -> None: ...
@overload
def update(
self, edges: Graph[_Node] | Iterable[_EdgePlus[_Node]] | None = None, nodes: Iterable[_Node] | None = None
self,
edges: Graph[_Node, _NodeData, _EdgeData] | Iterable[_EdgePlus[_Node, _EdgeData]] | None = None,
nodes: Iterable[_Node] | None = None,
) -> None: ...
def has_edge(self, u: _Node, v: _Node) -> bool: ...
def neighbors(self, n: _Node) -> Iterator[_Node]: ...
@cached_property
# Including subtypes' possible return types for LSP
def edges(self) -> EdgeView[_Node] | OutEdgeView[_Node]: ...
def get_edge_data(self, u: _Node, v: _Node, default: Any = None) -> dict[str, Any]: ...
def edges(self) -> EdgeView[_Node, _NodeData, _EdgeData] | OutEdgeView[_Node, _NodeData, _EdgeData]: ...
def get_edge_data(self, u: _Node, v: _Node, default: Any = None) -> _EdgeData: ...
# default: any Python object
def adjacency(self) -> Iterator[tuple[_Node, dict[_Node, dict[str, Any]]]]: ...
def adjacency(self) -> Iterator[tuple[_Node, dict[_Node, _EdgeData]]]: ...
@cached_property
# Including subtypes' possible return types for LSP
def degree(self) -> DegreeView[_Node] | DiDegreeView[_Node]: ...
def degree(self) -> DegreeView[_Node, _NodeData, _EdgeData] | DiDegreeView[_Node, _NodeData, _EdgeData]: ...
def clear(self) -> None: ...
def clear_edges(self) -> None: ...
def is_multigraph(self) -> bool: ...
def is_directed(self) -> bool: ...
def copy(self, as_view: bool = False) -> Self: ...
def to_directed(self, as_view: bool = False) -> DiGraph[_Node]: ...
def to_undirected(self, as_view: bool = False) -> Graph[_Node]: ...
def to_directed(self, as_view: bool = False) -> DiGraph[_Node, _NodeData, _EdgeData]: ...
def to_undirected(self, as_view: bool = False) -> Graph[_Node, _NodeData, _EdgeData]: ...
def subgraph(self, nodes: _NBunch[_Node]) -> Self: ...
def edge_subgraph(self, edges: Iterable[_Edge[_Node]]) -> Self: ...
@overload
Expand Down
Loading