diff --git a/stubs/networkx/networkx/algorithms/lowest_common_ancestors.pyi b/stubs/networkx/networkx/algorithms/lowest_common_ancestors.pyi index ab7a8e5472cd..7de4949ccb7d 100644 --- a/stubs/networkx/networkx/algorithms/lowest_common_ancestors.pyi +++ b/stubs/networkx/networkx/algorithms/lowest_common_ancestors.pyi @@ -1,17 +1,26 @@ -from _typeshed import Incomplete -from collections.abc import Generator +from collections.abc import Generator, Iterable +from typing import overload +from typing_extensions import TypeVar from networkx.classes.digraph import DiGraph from networkx.classes.graph import _Node from networkx.utils.backends import _dispatchable +_DefaultT = TypeVar("_DefaultT") + __all__ = ["all_pairs_lowest_common_ancestor", "tree_all_pairs_lowest_common_ancestor", "lowest_common_ancestor"] @_dispatchable -def all_pairs_lowest_common_ancestor(G: DiGraph[_Node], pairs=None): ... +def all_pairs_lowest_common_ancestor( + G: DiGraph[_Node], pairs: Iterable[tuple[_Node, _Node]] | None = None +) -> Generator[tuple[tuple[_Node, _Node], _Node | None]]: ... +@overload +@_dispatchable +def lowest_common_ancestor(G: DiGraph[_Node], node1: _Node, node2: _Node, default: None = None) -> _Node | None: ... +@overload @_dispatchable -def lowest_common_ancestor(G: DiGraph[_Node], node1, node2, default=None): ... +def lowest_common_ancestor(G: DiGraph[_Node], node1: _Node, node2: _Node, default: _DefaultT) -> _Node | _DefaultT: ... @_dispatchable def tree_all_pairs_lowest_common_ancestor( - G: DiGraph[_Node], root: _Node | None = None, pairs=None -) -> Generator[Incomplete, None, None]: ... + G: DiGraph[_Node], root: _Node | None = None, pairs: Iterable[tuple[_Node, _Node]] | None = None +) -> Generator[tuple[tuple[_Node, _Node], _Node]]: ... diff --git a/stubs/networkx/networkx/classes/graph.pyi b/stubs/networkx/networkx/classes/graph.pyi index ffdab103eaad..6335078252b1 100644 --- a/stubs/networkx/networkx/classes/graph.pyi +++ b/stubs/networkx/networkx/classes/graph.pyi @@ -8,6 +8,7 @@ from networkx.classes.coreviews import AdjacencyView, AtlasView from networkx.classes.digraph import DiGraph from networkx.classes.reportviews import DegreeView, EdgeView, NodeView +_DefaultT = TypeVar("_DefaultT") _Node = TypeVar("_Node", bound=Hashable) _NodeWithData: TypeAlias = tuple[_Node, dict[str, Any]] _NodePlus: TypeAlias = _Node | _NodeWithData[_Node] @@ -82,7 +83,10 @@ class Graph(Collection[_Node]): def neighbors(self, n: _Node) -> Iterator[_Node]: ... @cached_property def edges(self) -> EdgeView[_Node]: ... - def get_edge_data(self, u: _Node, v: _Node, default: Any = None) -> dict[str, Any]: ... + @overload + def get_edge_data(self, u: _Node, v: _Node, default: None = None) -> dict[str, Any] | None: ... + @overload + def get_edge_data(self, u: _Node, v: _Node, default: _DefaultT) -> dict[str, Any] | _DefaultT: ... # default: any Python object def adjacency(self) -> Iterator[tuple[_Node, dict[_Node, dict[str, Any]]]]: ... @cached_property diff --git a/stubs/networkx/networkx/classes/multigraph.pyi b/stubs/networkx/networkx/classes/multigraph.pyi index d0bb1ef27c82..dc40c4e868a9 100644 --- a/stubs/networkx/networkx/classes/multigraph.pyi +++ b/stubs/networkx/networkx/classes/multigraph.pyi @@ -29,18 +29,25 @@ class MultiGraph(Graph[_Node]): def remove_edge(self, u: _Node, v: _Node, key: Hashable | None = None) -> None: ... def has_edge(self, u: _Node, v: _Node, key: Hashable | None = None) -> bool: ... @overload # type: ignore[override] - def get_edge_data( - self, u: _Node, v: _Node, key: Hashable, default: _DefaultT | None = None - ) -> dict[str, Any] | _DefaultT: ... + def get_edge_data(self, u: _Node, v: _Node, key: Hashable, default: None = None) -> dict[str, Any] | None: ... + # key : hashable identifier, optional (default=None). + # Returns : The edge attribute dictionary. + @overload # type: ignore[override] + def get_edge_data(self, u: _Node, v: _Node, key: Hashable, default: _DefaultT) -> dict[str, Any] | _DefaultT: ... # key : hashable identifier, optional (default=None). # default : any Python object (default=None). Value to return if the specific edge (u, v, key) is not found. - # Returns: The edge attribute dictionary. + # Returns : The edge attribute dictionary. + @overload + def get_edge_data( + self, u: _Node, v: _Node, key: None = None, default: None = None + ) -> dict[Hashable, dict[str, Any] | None]: ... + # Returns : A dictionary mapping edge keys to attribute dictionaries for each of those edges if no specific key is provided. @overload def get_edge_data( - self, u: _Node, v: _Node, key: None = None, default: _DefaultT | None = None + self, u: _Node, v: _Node, key: None = None, *, default: _DefaultT ) -> dict[Hashable, dict[str, Any] | _DefaultT]: ... # default : any Python object (default=None). Value to return if there are no edges between u and v and no key is specified. - # Returns: A dictionary mapping edge keys to attribute dictionaries for each of those edges if no specific key is provided. + # Returns : A dictionary mapping edge keys to attribute dictionaries for each of those edges if no specific key is provided. def copy(self, as_view: bool = False) -> MultiGraph[_Node]: ... def to_directed(self, as_view: bool = False) -> MultiDiGraph[_Node]: ... def to_undirected(self, as_view: bool = False) -> MultiGraph[_Node]: ...