Skip to content
Open
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
22 changes: 13 additions & 9 deletions stubs/networkx/networkx/classes/reportviews.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from _typeshed import Incomplete, Unused
from abc import ABC
from collections.abc import Iterable, Iterator, Mapping, Set as AbstractSet
from typing import Generic, Literal, TypeVar, overload
from typing import Any, Generic, Literal, TypeVar, overload
from typing_extensions import Self

from networkx.classes.graph import Graph, _Edge, _EdgeData, _NBunch, _Node, _NodeData
Expand Down Expand Up @@ -43,22 +43,26 @@ class NodeView(Mapping[_Node, _NodeData], AbstractSet[_Node], Generic[_Node, _No
def __contains__(self, n: object) -> bool: ...

@overload
def __call__(self, data: Literal[False] = False, default=None) -> Self: ...
def __call__(self, data: Literal[False] = False) -> Self: ...
@overload
def __call__(self, data: Literal[True] | str, default=None) -> NodeDataView[_Node, _NodeData, _EdgeData]: ...
def __call__(self, data: Literal[True]) -> NodeDataView[_Node, _NodeData]: ...
@overload
def __call__(self, data: str, default: _U | None = None) -> NodeDataView[_Node, _U]: ...

@overload
def data(self, data: Literal[False], default=None) -> Self: ...
def data(self, data: Literal[False]) -> Self: ...
@overload
def data(self, data: Literal[True] = True) -> NodeDataView[_Node, _NodeData]: ...
@overload
def data(self, data: Literal[True] | str = True, default=None) -> NodeDataView[_Node, _NodeData, _EdgeData]: ...
def data(self, data: str, default: _U | None = None) -> NodeDataView[_Node, _U]: ...

class NodeDataView(AbstractSet[_Node], Generic[_Node, _NodeData, _EdgeData]):
class NodeDataView(AbstractSet[_Node], Generic[_Node, _D]):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change _NodeData?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NodeDataView previously always yielded tuple[_Node, _NodeData], which is wrong when data is a string — in that case the view yields the value stored under that attribute key, not the node's data mapping. So the second type parameter now describes the yielded value type (_D) rather than the node-data mapping, and the unused _EdgeData parameter was dropped. This mirrors OutEdgeDataView[_Node, _D] in the same file, which parameterises its yielded element the same way.

__slots__ = ("_nodes", "_data", "_default")
def __init__(self, nodedict: _NodeData, data: bool | str = False, default=None) -> None: ...
def __init__(self, nodedict: Mapping[_Node, Mapping[str, Any]], data: bool | str = False, default: Any = None) -> None: ...
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[tuple[_Node, _NodeData]]: ... # type: ignore[override]
def __iter__(self) -> Iterator[tuple[_Node, _D]]: ... # type: ignore[override]
def __contains__(self, n: object) -> bool: ...
def __getitem__(self, n: _Node) -> _NodeData | Incomplete: ...
def __getitem__(self, n: _Node) -> _D: ...

class DiDegreeView(Generic[_Node, _NodeData, _EdgeData]):
def __init__(
Expand Down
Loading