Skip to content
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

add annotations for MultiDiGraph #13319

Merged
merged 7 commits into from
Feb 26, 2025
Merged
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: 2 additions & 0 deletions stubs/networkx/networkx/classes/multidigraph.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class MultiDiGraph(MultiGraph[_Node], DiGraph[_Node]):
@cached_property
def pred(self) -> MultiAdjacencyView[_Node, _Node, dict[str, Incomplete]]: ...
@cached_property
def edges(self) -> OutMultiEdgeView[_Node]: ...
Copy link
Contributor

Choose a reason for hiding this comment

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

This part lgtm

@cached_property
def out_edges(self) -> OutMultiEdgeView[_Node]: ...
@cached_property
def in_edges(self) -> OutMultiEdgeView[_Node]: ...
Expand Down
48 changes: 39 additions & 9 deletions stubs/networkx/networkx/classes/reportviews.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -110,36 +110,66 @@ class EdgeView(OutEdgeView[_Node]): ...
class InEdgeView(OutEdgeView[_Node]): ...

class OutMultiEdgeView(OutEdgeView[_Node]):
def __iter__(self) -> Iterator[tuple[_Node, _Node, Incomplete]]: ... # type: ignore[override]
def __getitem__(self, e: tuple[_Node, _Node, Incomplete]) -> dict[str, Any]: ... # type: ignore[override]
@overload # type: ignore[override] # Has an additional `keys` keyword argument
def __call__(
def __call__( # type: ignore[overload-overlap]
self, nbunch: None = None, data: Literal[False] = False, *, default: Unused = None, keys: Literal[True]
) -> Self: ...
@overload
def __call__(
self, nbunch: _NBunch[_Node], data: Literal[True], *, default: None = None, keys: bool = False
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we rearrange the overloads so that the true/false pairs are next to each other so it's easier to read?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean exactly?

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct me if I'm wrong here, but it appears this PR splits some bool overloads into two separate overloads that take True and False. I'm wondering if we could arrange the order of the overload declarations so that if the original ordering was

@overload
overload1
@overload
overload2

It would now be

@overload
overload1True
@overload
overload1False
@overload
overload2True
@overload
overload2False

etc.

That would make it a bit easier to review and probably also easier to edit/maintain in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I followed the order of OutEdgeView for nbunch, data, etc., and so changing the order would make it inconsistent with the rest of the file.

) -> OutMultiEdgeDataView[_Node, tuple[_Node, _Node, dict[str, Incomplete]]]: ...
self, nbunch: _NBunch[_Node] = None, data: Literal[False] = False, *, default: None = None, keys: Literal[False] = False
) -> OutMultiEdgeDataView[_Node, tuple[_Node, _Node]]: ...
@overload
def __call__(
self, nbunch: _Node | Iterable[_Node], data: Literal[False] = False, *, default: None = None, keys: Literal[True]
) -> OutMultiEdgeDataView[_Node, tuple[_Node, _Node, Incomplete]]: ...
@overload
def __call__(
self, nbunch: _NBunch[_Node] = None, *, data: Literal[True], default: None = None, keys: Literal[True]
) -> OutMultiEdgeDataView[_Node, tuple[_Node, _Node, Incomplete, dict[str, Incomplete]]]: ...
@overload
def __call__(
self, nbunch: _NBunch[_Node], data: Literal[True], *, default: None = None, keys: Literal[True]
) -> OutMultiEdgeDataView[_Node, tuple[_Node, _Node, Incomplete, dict[str, Incomplete]]]: ...
@overload
def __call__(
self, nbunch: _NBunch[_Node] = None, *, data: Literal[True], default: None = None, keys: bool = False
self, nbunch: _NBunch[_Node] = None, *, data: Literal[True], default: None = None, keys: Literal[False] = False
) -> OutMultiEdgeDataView[_Node, tuple[_Node, _Node, dict[str, Incomplete]]]: ...
@overload
def __call__(
self, nbunch: _NBunch[_Node], data: str, *, default: _U | None = None, keys: bool = False
self, nbunch: _NBunch[_Node], data: str, *, default: _U | None = None, keys: Literal[False] = False
) -> OutMultiEdgeDataView[_Node, tuple[_Node, _Node, _U]]: ...
@overload
def __call__(
self, nbunch: _NBunch[_Node] = None, *, data: str, default: _U | None = None, keys: bool = False
self, nbunch: _NBunch[_Node] = None, *, data: str, default: _U | None = None, keys: Literal[True]
) -> OutMultiEdgeDataView[_Node, tuple[_Node, _Node, Incomplete, _U]]: ...
@overload
def __call__(
self, nbunch: _NBunch[_Node] = None, *, data: str, default: _U | None = None, keys: Literal[False] = False
) -> OutMultiEdgeDataView[_Node, tuple[_Node, _Node, _U]]: ...
@overload # type: ignore[override]
def data(self, data: Literal[False], default: Unused = None, nbunch: None = None, *, keys: Literal[True]) -> Self: ...
@overload
def data(self, data: Literal[False], default: Unused = None, nbunch: None = None, keys: Literal[False] = False) -> Self: ...
def data(
self, data: Literal[False], default: None = None, nbunch: _NBunch[_Node] = None, keys: Literal[False] = False
) -> OutMultiEdgeDataView[_Node, tuple[_Node, _Node]]: ...
@overload
def data(
self, data: Literal[True] = True, default: None = None, nbunch: _NBunch[_Node] = None, keys: bool = False
self, data: Literal[True] = True, default: None = None, nbunch: _NBunch[_Node] = None, keys: Literal[False] = False
) -> OutMultiEdgeDataView[_Node, tuple[_Node, _Node, dict[str, Incomplete]]]: ...
@overload
def data(
self, data: str, default: _U | None = None, nbunch: _NBunch[_Node] = None, keys: bool = False
self, data: Literal[True] = True, default: None = None, nbunch: _NBunch[_Node] = None, *, keys: Literal[True]
) -> OutMultiEdgeDataView[_Node, tuple[_Node, _Node, Incomplete, dict[str, Incomplete]]]: ...
@overload
def data(
self, data: str, default: _U | None = None, nbunch: _NBunch[_Node] = None, keys: Literal[False] = False
) -> OutMultiEdgeDataView[_Node, tuple[_Node, _Node, _U]]: ...
@overload
def data(
self, data: str, default: _U | None = None, nbunch: _NBunch[_Node] = None, *, keys: Literal[True]
) -> OutMultiEdgeDataView[_Node, tuple[_Node, _Node, Incomplete, _U]]: ...

class MultiEdgeView(OutMultiEdgeView[_Node]): ...
class InMultiEdgeView(OutMultiEdgeView[_Node]): ...