Skip to content
Closed
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,18 @@
assert_type(degree_view(""), int)
assert_type(degree_view([""]), DegreeView[str])
assert_type(degree_view({""}), DegreeView[str])

# Test set_edge_attributes and set_node_attributes with scalar values (issue #16542)
nx.set_edge_attributes(G, 5, "weight")

Check failure on line 28 in stubs/networkx/@tests/test_cases/check_tricky_function_params-py312.py

View workflow job for this annotation

GitHub Actions / pyright: regression tests (Linux, 3.13)

Type of "set_edge_attributes" is partially unknown   Type of "set_edge_attributes" is "Overload[(G: Graph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: object, name: str, *, backend: str | None = None, **backend_kwargs: Unknown) -> None, (G: MultiGraph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[tuple[_Node@set_edge_attributes, _Node@set_edge_attributes, Any], Any], name: None = None, *, backend: str | None = None, **backend_kwargs: Unknown) -> None, (G: Graph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[tuple[_Node@set_edge_attributes, _Node@set_edge_attributes], Any], name: None = None, *, backend: str | None = None, **backend_kwargs: Unknown) -> None]" (reportUnknownMemberType)
nx.set_edge_attributes(G, "red", name="color")

Check failure on line 29 in stubs/networkx/@tests/test_cases/check_tricky_function_params-py312.py

View workflow job for this annotation

GitHub Actions / pyright: regression tests (Linux, 3.13)

Type of "set_edge_attributes" is partially unknown   Type of "set_edge_attributes" is "Overload[(G: Graph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: object, name: str, *, backend: str | None = None, **backend_kwargs: Unknown) -> None, (G: MultiGraph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[tuple[_Node@set_edge_attributes, _Node@set_edge_attributes, Any], Any], name: None = None, *, backend: str | None = None, **backend_kwargs: Unknown) -> None, (G: Graph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[tuple[_Node@set_edge_attributes, _Node@set_edge_attributes], Any], name: None = None, *, backend: str | None = None, **backend_kwargs: Unknown) -> None]" (reportUnknownMemberType)
nx.set_edge_attributes(G, {(1, 2): 10}, "capacity")

Check failure on line 30 in stubs/networkx/@tests/test_cases/check_tricky_function_params-py312.py

View workflow job for this annotation

GitHub Actions / pyright: regression tests (Linux, 3.13)

Type of "set_edge_attributes" is partially unknown   Type of "set_edge_attributes" is "Overload[(G: Graph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: object, name: str, *, backend: str | None = None, **backend_kwargs: Unknown) -> None, (G: MultiGraph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[tuple[_Node@set_edge_attributes, _Node@set_edge_attributes, Any], Any], name: None = None, *, backend: str | None = None, **backend_kwargs: Unknown) -> None, (G: Graph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[tuple[_Node@set_edge_attributes, _Node@set_edge_attributes], Any], name: None = None, *, backend: str | None = None, **backend_kwargs: Unknown) -> None]" (reportUnknownMemberType)
nx.set_edge_attributes(G, {(1, 2): {"weight": 10}})

Check failure on line 31 in stubs/networkx/@tests/test_cases/check_tricky_function_params-py312.py

View workflow job for this annotation

GitHub Actions / pyright: regression tests (Linux, 3.13)

Type of "set_edge_attributes" is partially unknown   Type of "set_edge_attributes" is "Overload[(G: Graph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: object, name: str, *, backend: str | None = None, **backend_kwargs: Unknown) -> None, (G: MultiGraph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[tuple[_Node@set_edge_attributes, _Node@set_edge_attributes, Any], Any], name: None = None, *, backend: str | None = None, **backend_kwargs: Unknown) -> None, (G: Graph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[tuple[_Node@set_edge_attributes, _Node@set_edge_attributes], Any], name: None = None, *, backend: str | None = None, **backend_kwargs: Unknown) -> None]" (reportUnknownMemberType)

MG: nx.MultiGraph[int] = nx.MultiGraph()
nx.set_edge_attributes(MG, 5, "weight")

Check failure on line 34 in stubs/networkx/@tests/test_cases/check_tricky_function_params-py312.py

View workflow job for this annotation

GitHub Actions / pyright: regression tests (Linux, 3.13)

Type of "set_edge_attributes" is partially unknown   Type of "set_edge_attributes" is "Overload[(G: Graph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: object, name: str, *, backend: str | None = None, **backend_kwargs: Unknown) -> None, (G: MultiGraph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[tuple[_Node@set_edge_attributes, _Node@set_edge_attributes, Any], Any], name: None = None, *, backend: str | None = None, **backend_kwargs: Unknown) -> None, (G: Graph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[tuple[_Node@set_edge_attributes, _Node@set_edge_attributes], Any], name: None = None, *, backend: str | None = None, **backend_kwargs: Unknown) -> None]" (reportUnknownMemberType)
nx.set_edge_attributes(MG, {(1, 2, 0): {"weight": 10}})

Check failure on line 35 in stubs/networkx/@tests/test_cases/check_tricky_function_params-py312.py

View workflow job for this annotation

GitHub Actions / pyright: regression tests (Linux, 3.13)

Type of "set_edge_attributes" is partially unknown   Type of "set_edge_attributes" is "Overload[(G: Graph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: object, name: str, *, backend: str | None = None, **backend_kwargs: Unknown) -> None, (G: MultiGraph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[tuple[_Node@set_edge_attributes, _Node@set_edge_attributes, Any], Any], name: None = None, *, backend: str | None = None, **backend_kwargs: Unknown) -> None, (G: Graph[_Node@set_edge_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[tuple[_Node@set_edge_attributes, _Node@set_edge_attributes], Any], name: None = None, *, backend: str | None = None, **backend_kwargs: Unknown) -> None]" (reportUnknownMemberType)

nx.set_node_attributes(G, 5, "cost")

Check failure on line 37 in stubs/networkx/@tests/test_cases/check_tricky_function_params-py312.py

View workflow job for this annotation

GitHub Actions / pyright: regression tests (Linux, 3.13)

Type of "set_node_attributes" is partially unknown   Type of "set_node_attributes" is "Overload[(G: Graph[_Node@set_node_attributes, dict[str, Any], dict[str, Any]], values: object, name: str, *, backend: Unknown | None = None, **backend_kwargs: Unknown) -> None, (G: Graph[_Node@set_node_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[_Node@set_node_attributes, SupportsKeysAndGetItem[Any, Any] | Iterable[tuple[Any, Any]]], name: None = None, *, backend: Unknown | None = None, **backend_kwargs: Unknown) -> None]" (reportUnknownMemberType)
nx.set_node_attributes(G, "red", name="color")

Check failure on line 38 in stubs/networkx/@tests/test_cases/check_tricky_function_params-py312.py

View workflow job for this annotation

GitHub Actions / pyright: regression tests (Linux, 3.13)

Type of "set_node_attributes" is partially unknown   Type of "set_node_attributes" is "Overload[(G: Graph[_Node@set_node_attributes, dict[str, Any], dict[str, Any]], values: object, name: str, *, backend: Unknown | None = None, **backend_kwargs: Unknown) -> None, (G: Graph[_Node@set_node_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[_Node@set_node_attributes, SupportsKeysAndGetItem[Any, Any] | Iterable[tuple[Any, Any]]], name: None = None, *, backend: Unknown | None = None, **backend_kwargs: Unknown) -> None]" (reportUnknownMemberType)
nx.set_node_attributes(G, {1: 10}, "cost")

Check failure on line 39 in stubs/networkx/@tests/test_cases/check_tricky_function_params-py312.py

View workflow job for this annotation

GitHub Actions / pyright: regression tests (Linux, 3.13)

Type of "set_node_attributes" is partially unknown   Type of "set_node_attributes" is "Overload[(G: Graph[_Node@set_node_attributes, dict[str, Any], dict[str, Any]], values: object, name: str, *, backend: Unknown | None = None, **backend_kwargs: Unknown) -> None, (G: Graph[_Node@set_node_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[_Node@set_node_attributes, SupportsKeysAndGetItem[Any, Any] | Iterable[tuple[Any, Any]]], name: None = None, *, backend: Unknown | None = None, **backend_kwargs: Unknown) -> None]" (reportUnknownMemberType)
nx.set_node_attributes(G, {1: {"cost": 10}})

Check failure on line 40 in stubs/networkx/@tests/test_cases/check_tricky_function_params-py312.py

View workflow job for this annotation

GitHub Actions / pyright: regression tests (Linux, 3.13)

Type of "set_node_attributes" is partially unknown   Type of "set_node_attributes" is "Overload[(G: Graph[_Node@set_node_attributes, dict[str, Any], dict[str, Any]], values: object, name: str, *, backend: Unknown | None = None, **backend_kwargs: Unknown) -> None, (G: Graph[_Node@set_node_attributes, dict[str, Any], dict[str, Any]], values: SupportsItems[_Node@set_node_attributes, SupportsKeysAndGetItem[Any, Any] | Iterable[tuple[Any, Any]]], name: None = None, *, backend: Unknown | None = None, **backend_kwargs: Unknown) -> None]" (reportUnknownMemberType)
20 changes: 13 additions & 7 deletions stubs/networkx/networkx/classes/function.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Incomplete, SupportsItems, SupportsKeysAndGetItem, Unused
from _typeshed import Incomplete, SupportsItems, SupportsKeysAndGetItem
from collections.abc import Callable, Collection, Generator, Iterable, Iterator
from typing import Literal, TypeVar, overload

Expand Down Expand Up @@ -82,11 +82,10 @@ 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],
values: object,
name: str,
*,
backend=None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload
Expand All @@ -110,7 +109,7 @@ def remove_node_attributes(G: Graph[_Node], *attr_names, nbunch=None) -> None: .
@overload
def set_edge_attributes(
G: Graph[_Node],
values: SupportsItems[tuple[_Node, _Node], Incomplete],
values: object,
name: str,
*,
backend: str | None = None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload
Expand All @@ -119,14 +118,21 @@ def set_edge_attributes(
@overload
def set_edge_attributes(
G: MultiGraph[_Node],
values: dict[tuple[_Node, _Node, Incomplete], Incomplete],
name: str,
values: SupportsItems[tuple[_Node, _Node, Incomplete], Incomplete],
name: None = None,
*,
backend: str | None = None,
**backend_kwargs,
) -> 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: SupportsItems[tuple[_Node, _Node], Incomplete],
name: None = None,
*,
backend: str | None = None,
**backend_kwargs,
) -> None: ...

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