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
21 changes: 15 additions & 6 deletions stubs/networkx/networkx/algorithms/lowest_common_ancestors.pyi
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +17 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that @overload does not work with @_dispatchable (see #14462 for more information). TLDR, you have to remove the dispatchable decorator if you want to use overloads. Here is a patch that passes stubtest:

diff --git a/stubs/networkx/networkx/algorithms/lowest_common_ancestors.pyi b/stubs/networkx/networkx/algorithms/lowest_common_ancestors.pyi
index 7de4949cc..3244759f3 100644
--- a/stubs/networkx/networkx/algorithms/lowest_common_ancestors.pyi
+++ b/stubs/networkx/networkx/algorithms/lowest_common_ancestors.pyi
@@ -15,11 +15,13 @@ 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: ...
+def lowest_common_ancestor(
+    G: DiGraph[_Node], node1: _Node, node2: _Node, default: None = None, *, backend: str | None = None, **backend_kwargs
+) -> _Node | None: ...
 @overload
-@_dispatchable
-def lowest_common_ancestor(G: DiGraph[_Node], node1: _Node, node2: _Node, default: _DefaultT) -> _Node | _DefaultT: ...
+def lowest_common_ancestor(
+    G: DiGraph[_Node], node1: _Node, node2: _Node, default: _DefaultT, *, backend: str | None = None, **backend_kwargs
+) -> _Node | _DefaultT: ...
 @_dispatchable
 def tree_all_pairs_lowest_common_ancestor(
     G: DiGraph[_Node], root: _Node | None = None, pairs: Iterable[tuple[_Node, _Node]] | None = None

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]]: ...
6 changes: 5 additions & 1 deletion stubs/networkx/networkx/classes/graph.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
19 changes: 13 additions & 6 deletions stubs/networkx/networkx/classes/multigraph.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...
Expand Down
Loading