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
20 changes: 12 additions & 8 deletions stubs/networkx/networkx/classes/reportviews.pyi
Original file line number Diff line number Diff line change
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, default: Unused = None) -> Self: ...

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.

I think we should try to remove the default argument for this branch to catch misuse of this API. If that doesn't work, try to use None as type argument.

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

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.

Same here.

@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], default: Unused = None) -> Self: ...
@overload
def data(self, data: Literal[True] = True, default: None = None) -> NodeDataView[_Node, _NodeData]: ...
Comment on lines +53 to +55

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.

See above.

@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?

__slots__ = ("_nodes", "_data", "_default")
def __init__(self, nodedict: _NodeData, data: bool | str = False, default=None) -> None: ...
def __init__(self, nodedict, data: bool | str = False, default: object = None) -> None: ...

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 remove the annotation for nodedict?

Why use object for default? How is it used?

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