Skip to content

networkx: fix subgraph and degree #14390

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion stubs/networkx/networkx/classes/graph.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Graph(Collection[_Node]):
def copy(self, as_view: bool = False) -> Self: ...
def to_directed(self, as_view: bool = False) -> DiGraph[_Node]: ...
def to_undirected(self, as_view: bool = False) -> Graph[_Node]: ...
def subgraph(self, nodes: Iterable[_Node]) -> Graph[_Node]: ...
def subgraph(self, nodes: _NBunch[_Node]) -> Graph[_Node]: ...
def edge_subgraph(self, edges: Iterable[_Edge[_Node]]) -> Graph[_Node]: ...
@overload
def size(self, weight: None = None) -> int: ...
Expand Down
7 changes: 6 additions & 1 deletion stubs/networkx/networkx/classes/reportviews.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ class NodeDataView(AbstractSet[_Node]):

class DiDegreeView(Generic[_Node]):
def __init__(self, G: Graph[_Node], nbunch: _NBunch[_Node] = None, weight: None | bool | str = None) -> None: ...
def __call__(self, nbunch: _NBunch[_Node] = None, weight: None | bool | str = None) -> int | DiDegreeView[_Node]: ...
@overload
def __call__(self, nbunch: None = None, weight: None | bool | str = None) -> Self: ...
@overload
def __call__(self, nbunch: _Node, weight: None | bool | str = None) -> int: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

__getitem__ returns float, so this should also return float:

Suggested change
def __call__(self, nbunch: _Node, weight: None | bool | str = None) -> int: ...
def __call__(self, nbunch: _Node, weight: None | bool | str = None) -> float: ...

Copy link
Contributor Author

@AckslD AckslD Jul 10, 2025

Choose a reason for hiding this comment

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

hmm shouldn't the degree always be an integer, at least this passes:

import networkx as nx
g = nx.Graph()
g.add_node('a')
assert type(g.degree('a')) is int

@overload
def __call__(self, nbunch: Iterable[_Node], weight: None | bool | str = None) -> Self: ...
def __getitem__(self, n: _Node) -> float: ...
def __iter__(self) -> Iterator[tuple[_Node, float]]: ...
def __len__(self) -> int: ...
Expand Down
Loading