Skip to content

Commit b017eb6

Browse files
authored
[networkx] Accept a Callable as relabel_nodes mapping (#16552)
1 parent d2b142b commit b017eb6

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎stubs/networkx/networkx/relabel.pyi‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections.abc import Hashable, Mapping
1+
from collections.abc import Callable, Hashable, Mapping
22
from typing import Literal, TypeVar, overload
33

44
from networkx.classes.digraph import DiGraph
@@ -13,13 +13,15 @@ _Y = TypeVar("_Y", bound=Hashable)
1313
__all__ = ["convert_node_labels_to_integers", "relabel_nodes"]
1414

1515
@overload
16-
def relabel_nodes(G: MultiDiGraph[_X], mapping: Mapping[_X, _Y], copy: bool = True) -> MultiDiGraph[_X | _Y]: ...
16+
def relabel_nodes(
17+
G: MultiDiGraph[_X], mapping: Mapping[_X, _Y] | Callable[[_X], _Y], copy: bool = True
18+
) -> MultiDiGraph[_X | _Y]: ...
1719
@overload
18-
def relabel_nodes(G: DiGraph[_X], mapping: Mapping[_X, _Y], copy: bool = True) -> DiGraph[_X | _Y]: ...
20+
def relabel_nodes(G: DiGraph[_X], mapping: Mapping[_X, _Y] | Callable[[_X], _Y], copy: bool = True) -> DiGraph[_X | _Y]: ...
1921
@overload
20-
def relabel_nodes(G: MultiGraph[_X], mapping: Mapping[_X, _Y], copy: bool = True) -> MultiGraph[_X | _Y]: ...
22+
def relabel_nodes(G: MultiGraph[_X], mapping: Mapping[_X, _Y] | Callable[[_X], _Y], copy: bool = True) -> MultiGraph[_X | _Y]: ...
2123
@overload
22-
def relabel_nodes(G: Graph[_X], mapping: Mapping[_X, _Y], copy: bool = True) -> Graph[_X | _Y]: ...
24+
def relabel_nodes(G: Graph[_X], mapping: Mapping[_X, _Y] | Callable[[_X], _Y], copy: bool = True) -> Graph[_X | _Y]: ...
2325

2426
@_dispatchable
2527
def convert_node_labels_to_integers(

0 commit comments

Comments
 (0)