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
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@
assert_type(degree_view(""), int)
assert_type(degree_view([""]), DegreeView[str])
assert_type(degree_view({""}), DegreeView[str])

# Test scalar attributes with name in set_node_attributes and set_edge_attributes
nx.set_node_attributes(G, 5, "some_name")
nx.set_node_attributes(G, {1: "val"}, "some_name")
nx.set_edge_attributes(G, 10, "weight")
nx.set_edge_attributes(G, {(1, 2): 10}, "weight")
27 changes: 18 additions & 9 deletions stubs/networkx/networkx/classes/function.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from _typeshed import Incomplete, SupportsItems, SupportsKeysAndGetItem, Unused
from collections.abc import Callable, Collection, Generator, Iterable, Iterator
from typing import Literal, TypeVar, overload
from typing import Any, Literal, TypeVar, overload

from networkx import _dispatchable
from networkx.algorithms.planarity import PlanarEmbedding
Expand Down Expand Up @@ -82,24 +82,27 @@ def to_directed(graph): ...
def to_undirected(graph): ...
def create_empty_copy(G: Graph[_Node], with_data: bool = True): ...

# incomplete: Can "Any scalar value" be enforced?
@overload
def set_node_attributes(
G: Graph[_Node],
values: SupportsItems[_Node, Unused],
name: str,
*,
backend=None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload
**backend_kwargs,
backend: str | None = None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload
**backend_kwargs: Any,
) -> None: ...
@overload
def set_node_attributes(
G: Graph[_Node],
values: SupportsItems[_Node, SupportsKeysAndGetItem[Incomplete, Incomplete] | Iterable[tuple[Incomplete, Incomplete]]],
name: None = None,
*,
backend=None,
**backend_kwargs,
backend: str | None = None,
**backend_kwargs: Any,
) -> None: ...
@overload
def set_node_attributes(
G: Graph[_Node], values: object, name: str, *, backend: str | None = None, **backend_kwargs: Any
) -> None: ...

@_dispatchable
Expand All @@ -114,7 +117,7 @@ def set_edge_attributes(
name: str,
*,
backend: str | None = None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload
**backend_kwargs,
**backend_kwargs: Any,
) -> None: ...
@overload
def set_edge_attributes(
Expand All @@ -123,10 +126,16 @@ def set_edge_attributes(
name: str,
*,
backend: str | None = None,
**backend_kwargs,
**backend_kwargs: Any,
) -> None: ...
@overload
def set_edge_attributes(G: Graph[_Node], values, name: None = None, *, backend: str | None = None, **backend_kwargs) -> None: ...
def set_edge_attributes(
G: Graph[_Node], values: object, name: str, *, backend: str | None = None, **backend_kwargs: Any
) -> None: ...
@overload
def set_edge_attributes(
G: Graph[_Node], values: Any, name: None = None, *, backend: str | None = None, **backend_kwargs: Any
) -> None: ...

@_dispatchable
def get_edge_attributes(G: Graph[_Node], name: str, default=None) -> dict[tuple[_Node, _Node], Incomplete]: ...
Expand Down
Loading