Repository navigation
Conversation
…et_node_attributes
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| *, | ||
| backend=None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload | ||
| **backend_kwargs, | ||
| backend: str | None = None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload |
There was a problem hiding this comment.
Let's also remove the comment, which doesn't help us much.
| backend=None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload | ||
| **backend_kwargs, | ||
| backend: str | None = None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload | ||
| **backend_kwargs: Any, |
There was a problem hiding this comment.
Why Any here? Please note that all uses of Any (except obvious ones) need to be documented. Could we reasonably replace **backend_kwargs with these kwargs? Then leave it unannotated, until we replace it. Are the backend_kwargs dependent on the particular backend (if there are multiple)? Document this here with a comment.
(More instances below.)
There was a problem hiding this comment.
Good point, reverted **backend_kwargs to be unannotated across all overloads.
| ) -> None: ... | ||
| @overload | ||
| def set_node_attributes( | ||
| G: Graph[_Node], values: object, name: str, *, backend: str | None = None, **backend_kwargs: Any |
There was a problem hiding this comment.
Same here.
Also, why is object used for values?
There was a problem hiding this comment.
NetworkX accepts any scalar or arbitrary Python object (integers, strings, floats, lists, etc.) when name is provided, setting it directly as the attribute value on each node/edge (G.nodes[n][name] = values). object seemed the most fitting type for an arbitrary scalar attribute value. For name=None, I reverted values to be unannotated as well.
| def set_edge_attributes( | ||
| G: Graph[_Node], values: object, name: str, *, backend: str | None = None, **backend_kwargs: Any | ||
| ) -> None: ... | ||
| @overload | ||
| def set_edge_attributes( | ||
| G: Graph[_Node], values: Any, name: None = None, *, backend: str | None = None, **backend_kwargs: Any | ||
| ) -> None: ... |
There was a problem hiding this comment.
Same problems as above: Why Any/object for values?
Address review feedback by leaving **backend_kwargs unannotated, reverting values to unannotated for set_edge_attributes when name is None, and removing obsolete @_dispatchable comments.
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Fixes #16542
NetworkX supports passing scalar values to
set_edge_attributesandset_node_attributeswhennameis provided (applying the scalar value to all edges or nodes). Added an overload acceptingvalues: object, name: strto both functions.