Skip to content

Add edges() override in MultiGraph to support the "keys" argument#13567

Merged
srittau merged 1 commit intopython:mainfrom
iconchris:networkx-multigragh-edges-fix
Mar 3, 2025
Merged

Add edges() override in MultiGraph to support the "keys" argument#13567
srittau merged 1 commit intopython:mainfrom
iconchris:networkx-multigragh-edges-fix

Conversation

@iconchris
Copy link
Copy Markdown
Contributor

Small fix to correct the typing for the edges() method of the MultiGraph class, which, adds a keys argument in order to differentiate multiple edges between the same pair of vertices.

Without this fix, code like:

for _sourceId, targetId, key, data in graph.edges(sourceId, data=True, keys=True):
  pass

...produces a mypy error like the following even though the code executes correctly:

graph.py:218: error: No overload variant of "__call__" of "OutEdgeView" matches argument types "str", "bool", "bool"  [call-overload]
graph.py:218: note: Possible overload variants:
graph.py:218: note:     def __call__(self, nbunch: None = ..., data: Literal[False] = ..., *, default: object = ...) -> OutEdgeView[Any]
graph.py:218: note:     def __call__(self, nbunch: Any | Iterable[Any], data: Literal[False] = ..., *, default: None = ...) -> OutEdgeDataView[Any, tuple[Any, Any]]
graph.py:218: note:     def __call__(self, nbunch: Any | Iterable[Any] | None, data: Literal[True], *, default: None = ...) -> OutEdgeDataView[Any, tuple[Any, Any, dict[str, Any]]]
graph.py:218: note:     def __call__(self, nbunch: Any | Iterable[Any] | None = ..., *, data: Literal[True], default: None = ...) -> OutEdgeDataView[Any, tuple[Any, Any, dict[str, Any]]]
graph.py:218: note:     def [_U] __call__(self, nbunch: Any | Iterable[Any] | None, data: str, *, default: _U | None = ...) -> OutEdgeDataView[Any, tuple[Any, Any, _U]]
graph.py:218: note:     def [_U] __call__(self, nbunch: Any | Iterable[Any] | None = ..., *, data: str, default: _U | None = ...) -> OutEdgeDataView[Any, tuple[Any, Any, _U]]

Thank you!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 1, 2025

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Copy Markdown
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

I have no experience with networkx, but the change looks sensible. Thanks!

@srittau srittau merged commit 336140b into python:main Mar 3, 2025
@iconchris iconchris deleted the networkx-multigragh-edges-fix branch March 3, 2025 15:09
mmingyu pushed a commit to mmingyu/typeshed that referenced this pull request May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants