Skip to content

Commit caeb62f

Browse files
[networkx] Accept any node type in graph functions that took Graph[Hashable] (#16557)
Graph is invariant in its node type, so Graph[Hashable] rejected Graph[str] and similar graphs. Use the _Node type variable, like the other functions in the module.
1 parent 5240732 commit caeb62f

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

‎stubs/networkx/networkx/classes/function.pyi‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from _typeshed import Incomplete, SupportsItems, SupportsKeysAndGetItem, Unused
2-
from collections.abc import Callable, Collection, Generator, Hashable, Iterable, Iterator
2+
from collections.abc import Callable, Collection, Generator, Iterable, Iterator
33
from typing import Literal, TypeVar, overload
44

55
from networkx import _dispatchable
@@ -63,11 +63,11 @@ def density(G: Graph[_Node]): ...
6363
def degree_histogram(G: Graph[_Node]) -> list[int]: ...
6464

6565
@overload
66-
def is_directed(G: PlanarEmbedding[Hashable]) -> Literal[False]: ... # type: ignore[misc] # Incompatible return types
66+
def is_directed(G: PlanarEmbedding[_Node]) -> Literal[False]: ... # type: ignore[misc] # Incompatible return types
6767
@overload
68-
def is_directed(G: DiGraph[Hashable]) -> Literal[True]: ... # type: ignore[misc] # Incompatible return types
68+
def is_directed(G: DiGraph[_Node]) -> Literal[True]: ... # type: ignore[misc] # Incompatible return types
6969
@overload
70-
def is_directed(G: Graph[Hashable]) -> Literal[False]: ...
70+
def is_directed(G: Graph[_Node]) -> Literal[False]: ...
7171

7272
def freeze(G: Graph[_Node]): ...
7373
def is_frozen(G: Graph[Incomplete]) -> bool: ...
@@ -85,7 +85,7 @@ def create_empty_copy(G: Graph[_Node], with_data: bool = True): ...
8585
# incomplete: Can "Any scalar value" be enforced?
8686
@overload
8787
def set_node_attributes(
88-
G: Graph[Hashable],
88+
G: Graph[_Node],
8989
values: SupportsItems[_Node, Unused],
9090
name: str,
9191
*,
@@ -126,9 +126,7 @@ def set_edge_attributes(
126126
**backend_kwargs,
127127
) -> None: ...
128128
@overload
129-
def set_edge_attributes(
130-
G: Graph[Hashable], values, name: None = None, *, backend: str | None = None, **backend_kwargs
131-
) -> None: ...
129+
def set_edge_attributes(G: Graph[_Node], values, name: None = None, *, backend: str | None = None, **backend_kwargs) -> None: ...
132130

133131
@_dispatchable
134132
def get_edge_attributes(G: Graph[_Node], name: str, default=None) -> dict[tuple[_Node, _Node], Incomplete]: ...
@@ -143,7 +141,7 @@ def is_weighted(G: Graph[_Node], edge: tuple[_Node, _Node] | None = None, weight
143141
@_dispatchable
144142
def is_negatively_weighted(G: Graph[_Node], edge: tuple[_Node, _Node] | None = None, weight: str = "weight") -> bool: ...
145143
@_dispatchable
146-
def is_empty(G: Graph[Hashable]) -> bool: ...
144+
def is_empty(G: Graph[_Node]) -> bool: ...
147145
def nodes_with_selfloops(G: Graph[_Node]) -> Generator[_Node]: ...
148146

149147
@overload
@@ -176,7 +174,7 @@ def selfloop_edges(
176174
) -> Generator[tuple[_Node, _Node, int, _U]]: ...
177175

178176
@_dispatchable
179-
def number_of_selfloops(G: Graph[Hashable]) -> int: ...
177+
def number_of_selfloops(G: Graph[_Node]) -> int: ...
180178
def is_path(G: Graph[_Node], path: Iterable[Incomplete]) -> bool: ...
181179
def path_weight(G: Graph[_Node], path: Collection[Incomplete], weight: str) -> int: ...
182180
def describe(G: Graph[_Node], describe_hook: Callable[[Graph[_Node]], dict[str, Incomplete]] | None = None) -> None: ...

0 commit comments

Comments
 (0)