Skip to content

complete networkx/...lowest_common_ancestors.pyi #14582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
18 changes: 12 additions & 6 deletions stubs/networkx/networkx/algorithms/lowest_common_ancestors.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
from _typeshed import Incomplete
from collections.abc import Generator
from collections.abc import Generator, Iterable
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]]: ...
@_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 | None = None
) -> _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]]: ...
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