-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
base: main
Are you sure you want to change the base?
Conversation
Hmm, |
Diff from mypy_primer, showing the effect of this PR on open source code: bokeh (https://github.com/bokeh/bokeh)
+ src/bokeh/models/util/structure.py:165: note: ... from here:
|
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.
Thanks, remarks below.
@overload | ||
def __call__(self, nbunch: _Node, weight: None | bool | str = None) -> int: ... | ||
@overload | ||
def __call__(self, nbunch: Iterable[_Node] | None = None, weight: None | bool | str = None) -> DiDegreeView[_Node]: ... |
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.
Probably overly pedantic, but this doesn't necessarily return a DiDegreeView
, but could also return a sub-class if called on an instance of a sub-class. So Self
is more appropriate:
def __call__(self, nbunch: Iterable[_Node] | None = None, weight: None | bool | str = None) -> DiDegreeView[_Node]: ... | |
def __call__(self, nbunch: Iterable[_Node] | None = None, weight: None | bool | str = None) -> Self: ... |
@@ -55,7 +55,10 @@ 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: _Node, weight: None | bool | str = None) -> int: ... |
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.
__getitem__
returns float
, so this should also return float
:
def __call__(self, nbunch: _Node, weight: None | bool | str = None) -> int: ... | |
def __call__(self, nbunch: _Node, weight: None | bool | str = None) -> float: ... |
Two small fixes to
networkx
, let me know if it's better with separate PRs:Graph.subgraph
can also take a single node.degree
takes a single node, the return type is different so addoverload
s.