-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
complete networkx/...lowest_common_ancestors.pyi #14582
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
… follows python#14509, python#14569 added TypeVar for parameter `default ` to class Graph: mirroring class MultiGraph
This comment has been minimized.
This comment has been minimized.
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, a few remarks below.
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
This comment has been minimized.
This comment has been minimized.
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.
Veni, vidi, submiti.
This comment has been minimized.
This comment has been minimized.
I tried a few things, nothing helped. I thought adding `networkx\.(algorithms\.)?(lowest_common_ancestors\.)?lowest_common_ancestor` to https://github.com/python/typeshed/blob/d270bb0dc1df3fcfae2808c9a5a0f7ec802e1fb2/stubs/networkx/%40tests/stubtest_allowlist.txt#L1-L11 would resolve the problem, but it didn't.
Diff from mypy_primer, showing the effect of this PR on open source code: discord.py (https://github.com/Rapptz/discord.py)
- discord/ext/commands/hybrid.py:508: error: Overlap between argument names and ** TypedDict items: "description", "name" [misc]
+ discord/ext/commands/hybrid.py:508: error: Overlap between argument names and ** TypedDict items: "name", "description" [misc]
- discord/ext/commands/hybrid.py:629: error: Overlap between argument names and ** TypedDict items: "description", "name" [misc]
+ discord/ext/commands/hybrid.py:629: error: Overlap between argument names and ** TypedDict items: "name", "description" [misc]
- discord/ext/commands/hybrid.py:834: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name" [misc]
+ discord/ext/commands/hybrid.py:834: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command" [misc]
- discord/ext/commands/hybrid.py:858: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name" [misc]
+ discord/ext/commands/hybrid.py:858: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command" [misc]
- discord/ext/commands/hybrid.py:883: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name" [misc]
+ discord/ext/commands/hybrid.py:883: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command" [misc]
- discord/ext/commands/hybrid.py:935: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name" [misc]
+ discord/ext/commands/hybrid.py:935: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command" [misc]
- discord/ext/commands/bot.py:291: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name" [misc]
+ discord/ext/commands/bot.py:291: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command" [misc]
- discord/ext/commands/bot.py:315: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name" [misc]
+ discord/ext/commands/bot.py:315: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command" [misc]
|
The changes LGTM. I'm a bit baffled why stubtest crashed. This is definitely a bug in stubtest that needs to be investigated. (Even if there was something wrong with the changes, it shouldn't crash, but print a proper error message.) |
Opened python/mypy#19689 to track the stubtest crash |
I've marked this PR as deferred for now until we get a stubtest fix (or a workaround). |
@overload | ||
@_dispatchable | ||
def lowest_common_ancestor(G: DiGraph[_Node], node1: _Node, node2: _Node, default: None = None) -> _Node | None: ... | ||
@overload | ||
@_dispatchable | ||
def lowest_common_ancestor(G: DiGraph[_Node], node1, node2, default=None): ... | ||
def lowest_common_ancestor(G: DiGraph[_Node], node1: _Node, node2: _Node, default: _DefaultT) -> _Node | _DefaultT: ... |
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.
Note that @overload
does not work with @_dispatchable
(see #14462 for more information). TLDR, you have to remove the dispatchable decorator if you want to use overloads. Here is a patch that passes stubtest:
diff --git a/stubs/networkx/networkx/algorithms/lowest_common_ancestors.pyi b/stubs/networkx/networkx/algorithms/lowest_common_ancestors.pyi
index 7de4949cc..3244759f3 100644
--- a/stubs/networkx/networkx/algorithms/lowest_common_ancestors.pyi
+++ b/stubs/networkx/networkx/algorithms/lowest_common_ancestors.pyi
@@ -15,11 +15,13 @@ def all_pairs_lowest_common_ancestor(
G: DiGraph[_Node], pairs: Iterable[tuple[_Node, _Node]] | None = None
) -> Generator[tuple[tuple[_Node, _Node], _Node | None]]: ...
@overload
-@_dispatchable
-def lowest_common_ancestor(G: DiGraph[_Node], node1: _Node, node2: _Node, default: None = None) -> _Node | None: ...
+def lowest_common_ancestor(
+ G: DiGraph[_Node], node1: _Node, node2: _Node, default: None = None, *, backend: str | None = None, **backend_kwargs
+) -> _Node | None: ...
@overload
-@_dispatchable
-def lowest_common_ancestor(G: DiGraph[_Node], node1: _Node, node2: _Node, default: _DefaultT) -> _Node | _DefaultT: ...
+def lowest_common_ancestor(
+ G: DiGraph[_Node], node1: _Node, node2: _Node, default: _DefaultT, *, backend: str | None = None, **backend_kwargs
+) -> _Node | _DefaultT: ...
@_dispatchable
def tree_all_pairs_lowest_common_ancestor(
G: DiGraph[_Node], root: _Node | None = None, pairs: Iterable[tuple[_Node, _Node]] | None = None
1. Should the stub have
|
# overloaded class-decorators are not properly supported in type-checkers: | |
# - mypy: https://github.com/python/mypy/issues/16840 | |
# - pyright: https://github.com/microsoft/pyright/issues/7167 | |
networkx\.(algorithms\.)?(boundary\.)?edge_boundary | |
networkx\.(algorithms\.)?(bridges\.)?local_bridges | |
networkx\.(algorithms\.)?(clique\.)?node_clique_number | |
networkx\.(convert_matrix\.)?from_numpy_array | |
networkx\.(convert_matrix\.)?from_pandas_adjacency | |
networkx\.(convert_matrix\.)?from_pandas_edgelist | |
networkx\.(generators\.)?(random_clustered\.)?random_clustered_graph | |
networkx\.(relabel\.)?relabel_nodes |
I think _dispatchable
is a "class-dispatcher", but I've never seen that term before, so I could be wrong.
class _dispatchable:
_is_testing = False
def __new__(
...
Therefore, I tried adding
networkx\.(algorithms\.)?(lowest_common_ancestors\.)?lowest_common_ancestor
to https://github.com/python/typeshed/blob/d270bb0dc1df3fcfae2808c9a5a0f7ec802e1fb2/stubs/networkx/%40tests/stubtest_allowlist.txt, but either I didn't do it correctly or it didn't help.
4. Note that "stubtest_allowlist.txt" has a special section just for _dispatchable
.
But I couldn't figure out if it was related or how to use the information to resolve the problem.
typeshed/stubs/networkx/@tests/stubtest_allowlist.txt
Lines 24 to 28 in d270bb0
# Stubtest says: "runtime argument "backend" has a default value of type None, which is | |
# incompatible with stub argument type builtins.str. This is often caused by overloads | |
# failing to account for explicitly passing in the default value." | |
# Which is true, but would require some way of concatenating `backend` to ParamSpec.kwargs | |
networkx\.(utils\.)?(backends\.)?_dispatchable\.__call__ |
addresses #14499 follows #14509, #14569
added TypeVar for parameter
default
to class Graph: mirroring class MultiGraphDeferred: Waiting for a stubtest fix: python/mypy#19689