Repository navigation
[networkx] Fix NodeDataView return type for string attribute in nodes(data=...) #16695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: ... | ||
| @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]: ... | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why change |
||
| __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: ... | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove the annotation for Why use |
||
| 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__( | ||
|
|
||
There was a problem hiding this comment.
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
defaultargument for this branch to catch misuse of this API. If that doesn't work, try to useNoneas type argument.