diff --git a/stubs/networkx/networkx/algorithms/approximation/maxcut.pyi b/stubs/networkx/networkx/algorithms/approximation/maxcut.pyi index 4518df47f2a1..cbda0146184e 100644 --- a/stubs/networkx/networkx/algorithms/approximation/maxcut.pyi +++ b/stubs/networkx/networkx/algorithms/approximation/maxcut.pyi @@ -1,4 +1,5 @@ from _typeshed import Incomplete +from collections.abc import Iterable from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable @@ -12,5 +13,8 @@ def randomized_partitioning( ) -> tuple[float, tuple[set[Incomplete], set[Incomplete]]]: ... @_dispatchable def one_exchange( - G: Graph[_Node], initial_cut: set[Incomplete] | None = None, seed: int | RandomState | None = None, weight: str | None = None + G: Graph[_Node], + initial_cut: Iterable[Incomplete] | None = None, + seed: int | RandomState | None = None, + weight: str | None = None, ) -> tuple[float, tuple[set[Incomplete], set[Incomplete]]]: ... diff --git a/stubs/networkx/networkx/algorithms/assortativity/correlation.pyi b/stubs/networkx/networkx/algorithms/assortativity/correlation.pyi index 78f36749726d..7029272e0899 100644 --- a/stubs/networkx/networkx/algorithms/assortativity/correlation.pyi +++ b/stubs/networkx/networkx/algorithms/assortativity/correlation.pyi @@ -23,3 +23,4 @@ def degree_pearson_correlation_coefficient( def attribute_assortativity_coefficient(G: Graph[_Node], attribute: str, nodes: Iterable[Incomplete] | None = None) -> float: ... @_dispatchable def numeric_assortativity_coefficient(G: Graph[_Node], attribute: str, nodes: Iterable[Incomplete] | None = None) -> float: ... +def attribute_ac(M) -> float: ... diff --git a/stubs/networkx/networkx/algorithms/bipartite/edgelist.pyi b/stubs/networkx/networkx/algorithms/bipartite/edgelist.pyi index de80e3d56b41..b0815f5d4aa6 100644 --- a/stubs/networkx/networkx/algorithms/bipartite/edgelist.pyi +++ b/stubs/networkx/networkx/algorithms/bipartite/edgelist.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete, StrPath, SupportsRead, SupportsWrite -from collections.abc import Collection, Generator, Iterable +from collections.abc import Callable, Collection, Generator, Iterable from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable @@ -12,28 +12,32 @@ def write_edgelist( path: StrPath | SupportsWrite[bytes], comments: str = "#", delimiter: str = " ", - data: bool = True, + data: bool | Collection[Incomplete] = True, # Not Iterable: iterated more than once, one-shot iterables give wrong results encoding: str = "utf-8", ) -> None: ... @_dispatchable -def generate_edgelist(G: Graph[_Node], delimiter: str = " ", data: bool = True) -> Generator[str]: ... +def generate_edgelist( + G: Graph[_Node], + delimiter: str = " ", + data: bool | Collection[Incomplete] = True, # Not Iterable: iterated more than once, one-shot iterables give wrong results +) -> Generator[str]: ... @_dispatchable def parse_edgelist( lines: Iterable[str], - comments: str | None = "#", + comments: str = "#", delimiter: str | None = None, create_using: Graph[_Node] | type[Graph[_Node]] | None = None, - nodetype: type[Incomplete] | None = None, - data: bool | Collection[tuple[str, type[Incomplete]]] = True, + nodetype: Callable[[str], Incomplete] | None = None, + data: bool | Collection[tuple[str, Callable[[str], Incomplete]]] = True, ) -> Graph[Incomplete]: ... @_dispatchable def read_edgelist( path: StrPath | SupportsRead[bytes], - comments: str | None = "#", + comments: str = "#", delimiter: str | None = None, create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None, - nodetype=None, - data: bool | Collection[tuple[str, type[Incomplete]]] = True, + nodetype: Callable[[str], Incomplete] | None = None, + data: bool | Collection[tuple[str, Callable[[str], Incomplete]]] = True, edgetype=None, - encoding: str | None = "utf-8", + encoding: str = "utf-8", ) -> Graph[Incomplete]: ... diff --git a/stubs/networkx/networkx/algorithms/bipartite/generators.pyi b/stubs/networkx/networkx/algorithms/bipartite/generators.pyi index cf5b9686cfb9..bac0f06547cf 100644 --- a/stubs/networkx/networkx/algorithms/bipartite/generators.pyi +++ b/stubs/networkx/networkx/algorithms/bipartite/generators.pyi @@ -1,5 +1,4 @@ -from _typeshed import Incomplete -from collections.abc import Iterable +from collections.abc import Sequence from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable @@ -20,26 +19,26 @@ __all__ = [ def complete_bipartite_graph(n1, n2, create_using: Graph[_Node] | type[Graph[_Node]] | None = None): ... @_dispatchable def configuration_model( - aseq: Iterable[Incomplete], - bseq: Iterable[Incomplete], + aseq: Sequence[int], + bseq: Sequence[int], create_using: Graph[_Node] | type[Graph[_Node]] | None = None, seed: int | RandomState | None = None, ): ... @_dispatchable def havel_hakimi_graph( - aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | type[Graph[_Node]] | None = None + aseq: Sequence[int], bseq: Sequence[int], create_using: Graph[_Node] | type[Graph[_Node]] | None = None ): ... @_dispatchable def reverse_havel_hakimi_graph( - aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | type[Graph[_Node]] | None = None + aseq: Sequence[int], bseq: Sequence[int], create_using: Graph[_Node] | type[Graph[_Node]] | None = None ): ... @_dispatchable def alternating_havel_hakimi_graph( - aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | type[Graph[_Node]] | None = None + aseq: Sequence[int], bseq: Sequence[int], create_using: Graph[_Node] | type[Graph[_Node]] | None = None ): ... @_dispatchable def preferential_attachment_graph( - aseq: Iterable[Incomplete], + aseq: Sequence[int], p: float, create_using: Graph[_Node] | type[Graph[_Node]] | None = None, seed: int | RandomState | None = None, diff --git a/stubs/networkx/networkx/algorithms/bipartite/matrix.pyi b/stubs/networkx/networkx/algorithms/bipartite/matrix.pyi index 18bca470ca7f..a013b60196d6 100644 --- a/stubs/networkx/networkx/algorithms/bipartite/matrix.pyi +++ b/stubs/networkx/networkx/algorithms/bipartite/matrix.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete -from collections.abc import Iterable +from collections.abc import Collection import numpy as np from networkx.classes.graph import Graph, _Node @@ -10,8 +10,8 @@ __all__ = ["biadjacency_matrix", "from_biadjacency_matrix"] @_dispatchable def biadjacency_matrix( G: Graph[_Node], - row_order: Iterable[_Node], - column_order: Iterable[Incomplete] | None = None, + row_order: Collection[_Node], + column_order: Collection[Incomplete] | None = None, dtype: np.dtype[Incomplete] | None = None, weight: str | None = "weight", format: str = "csr", @@ -22,6 +22,6 @@ def from_biadjacency_matrix( create_using: Graph[_Node] | type[Graph[_Node]] | None = None, edge_attribute: str = "weight", *, - row_order: Iterable[Incomplete] | None = None, - column_order: Iterable[Incomplete] | None = None, + row_order: Collection[Incomplete] | None = None, + column_order: Collection[Incomplete] | None = None, ) -> Graph[Incomplete]: ... diff --git a/stubs/networkx/networkx/algorithms/bipartite/projection.pyi b/stubs/networkx/networkx/algorithms/bipartite/projection.pyi index 3d383557dbf5..16f170368ccc 100644 --- a/stubs/networkx/networkx/algorithms/bipartite/projection.pyi +++ b/stubs/networkx/networkx/algorithms/bipartite/projection.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete -from collections.abc import Callable, Iterable +from collections.abc import Callable, Collection from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable @@ -13,14 +13,26 @@ __all__ = [ ] @_dispatchable -def projected_graph(B: Graph[_Node], nodes: Iterable[Incomplete], multigraph: bool = False) -> Graph[Incomplete]: ... +def projected_graph( + B: Graph[_Node], + nodes: Collection[Incomplete], # Not Iterable: iterated more than once, one-shot iterables give wrong results + multigraph: bool = False, +) -> Graph[Incomplete]: ... @_dispatchable -def weighted_projected_graph(B: Graph[_Node], nodes: Iterable[Incomplete], ratio: bool = False) -> Graph[Incomplete]: ... +def weighted_projected_graph(B: Graph[_Node], nodes: Collection[Incomplete], ratio: bool = False) -> Graph[Incomplete]: ... @_dispatchable -def collaboration_weighted_projected_graph(B: Graph[_Node], nodes: Iterable[Incomplete]) -> Graph[Incomplete]: ... +def collaboration_weighted_projected_graph( + B: Graph[_Node], nodes: Collection[Incomplete] # Not Iterable: iterated more than once, one-shot iterables give wrong results +) -> Graph[Incomplete]: ... @_dispatchable -def overlap_weighted_projected_graph(B: Graph[_Node], nodes: Iterable[Incomplete], jaccard: bool = True) -> Graph[Incomplete]: ... +def overlap_weighted_projected_graph( + B: Graph[_Node], + nodes: Collection[Incomplete], # Not Iterable: iterated more than once, one-shot iterables give wrong results + jaccard: bool = True, +) -> Graph[Incomplete]: ... @_dispatchable def generic_weighted_projected_graph( - B: Graph[_Node], nodes: Iterable[Incomplete], weight_function: Callable[..., Incomplete] | None = None + B: Graph[_Node], + nodes: Collection[Incomplete], # Not Iterable: iterated more than once, one-shot iterables give wrong results + weight_function: Callable[..., Incomplete] | None = None, ) -> Graph[Incomplete]: ... diff --git a/stubs/networkx/networkx/algorithms/boundary.pyi b/stubs/networkx/networkx/algorithms/boundary.pyi index 358ed74eb197..5e500cbbbb3c 100644 --- a/stubs/networkx/networkx/algorithms/boundary.pyi +++ b/stubs/networkx/networkx/algorithms/boundary.pyi @@ -13,7 +13,7 @@ def edge_boundary( G: Graph[_Node], nbunch1: Iterable[Incomplete], nbunch2: Iterable[Incomplete] | None = None, - data=False, + data: bool | str = False, keys: bool = False, default=None, ) -> Generator[tuple[_Node, _Node]]: ... @@ -22,7 +22,7 @@ def edge_boundary( G: Graph[_Node], nbunch1: Iterable[Incomplete], nbunch2: Iterable[Incomplete] | None = None, - data=False, + data: bool | str = False, keys: bool = False, default=None, ) -> Generator[tuple[_Node, _Node, dict[str, Incomplete]]]: ... @@ -31,7 +31,7 @@ def edge_boundary( G: Graph[_Node], nbunch1: Iterable[Incomplete], nbunch2: Iterable[Incomplete] | None = None, - data=False, + data: bool | str = False, keys: bool = False, default=None, ) -> Generator[tuple[_Node, _Node, dict[str, Incomplete]]]: ... @@ -40,7 +40,7 @@ def edge_boundary( G: Graph[_Node], nbunch1: Iterable[Incomplete], nbunch2: Iterable[Incomplete] | None = None, - data=False, + data: bool | str = False, keys: bool = False, default: _U | None = None, ) -> Generator[tuple[_Node, _Node, dict[str, _U]]]: ... @@ -49,7 +49,7 @@ def edge_boundary( G: Graph[_Node], nbunch1: Iterable[Incomplete], nbunch2: Iterable[Incomplete] | None = None, - data=False, + data: bool | str = False, keys: bool = False, default: _U | None = None, ) -> Generator[tuple[_Node, _Node, dict[str, _U]]]: ... @@ -58,7 +58,7 @@ def edge_boundary( G: Graph[_Node], nbunch1: Iterable[Incomplete], nbunch2: Iterable[Incomplete] | None = None, - data=False, + data: bool | str = False, keys: bool = False, default=None, ) -> Generator[tuple[_Node, _Node, int]]: ... @@ -67,7 +67,7 @@ def edge_boundary( G: Graph[_Node], nbunch1: Iterable[Incomplete], nbunch2: Iterable[Incomplete] | None = None, - data=False, + data: bool | str = False, keys: bool = False, default=None, ) -> Generator[tuple[_Node, _Node, int]]: ... @@ -76,7 +76,7 @@ def edge_boundary( G: Graph[_Node], nbunch1: Iterable[Incomplete], nbunch2: Iterable[Incomplete] | None = None, - data=False, + data: bool | str = False, keys: bool = False, default=None, ) -> Generator[tuple[_Node, _Node, int, dict[str, Incomplete]]]: ... @@ -85,7 +85,7 @@ def edge_boundary( G: Graph[_Node], nbunch1: Iterable[Incomplete], nbunch2: Iterable[Incomplete] | None = None, - data=False, + data: bool | str = False, keys: bool = False, default=None, ) -> Generator[tuple[_Node, _Node, int, dict[str, Incomplete]]]: ... @@ -94,7 +94,7 @@ def edge_boundary( G: Graph[_Node], nbunch1: Iterable[Incomplete], nbunch2: Iterable[Incomplete] | None = None, - data=False, + data: bool | str = False, keys: bool = False, default: _U | None = None, ) -> Generator[tuple[_Node, _Node, int, dict[str, _U]]]: ... @@ -103,7 +103,7 @@ def edge_boundary( G: Graph[_Node], nbunch1: Iterable[Incomplete], nbunch2: Iterable[Incomplete] | None = None, - data=False, + data: bool | str = False, keys: bool = False, default: _U | None = None, ) -> Generator[tuple[_Node, _Node, int, dict[str, _U]]]: ... diff --git a/stubs/networkx/networkx/algorithms/clique.pyi b/stubs/networkx/networkx/algorithms/clique.pyi index 225fc56a64e6..b1186869341f 100644 --- a/stubs/networkx/networkx/algorithms/clique.pyi +++ b/stubs/networkx/networkx/algorithms/clique.pyi @@ -35,11 +35,13 @@ def make_clique_bipartite( ) -> Graph[_Node]: ... @overload -def node_clique_number( - G: Graph[_Node], nodes=None, cliques: Iterable[Incomplete] | None = None, separate_nodes=False +def node_clique_number( # type: ignore[overload-overlap] + G: Graph[_Node], nodes: Iterable[_Node] | None = None, cliques: Iterable[Incomplete] | None = None, separate_nodes=False ) -> dict[_Node, int]: ... @overload -def node_clique_number(G: Graph[_Node], nodes=None, cliques: Iterable[Incomplete] | None = None, separate_nodes=False) -> int: ... +def node_clique_number( + G: Graph[_Node], nodes: _Node, cliques: Iterable[Incomplete] | None = None, separate_nodes=False +) -> int: ... def number_of_cliques( G: Graph[_Node], nodes: list[_Node] | _Node | None = None, cliques: Iterable[Incomplete] | None = None diff --git a/stubs/networkx/networkx/algorithms/isomorphism/ismags.pyi b/stubs/networkx/networkx/algorithms/isomorphism/ismags.pyi index 2f7db7c1ec00..99bca2087d37 100644 --- a/stubs/networkx/networkx/algorithms/isomorphism/ismags.pyi +++ b/stubs/networkx/networkx/algorithms/isomorphism/ismags.pyi @@ -2,6 +2,8 @@ from _typeshed import Incomplete from collections.abc import Callable, Generator, Hashable, Iterable from typing import Any +from ...classes.graph import Graph + __all__ = ["ISMAGS"] def are_all_equal(iterable: Iterable[Any]) -> bool: ... @@ -21,7 +23,15 @@ class ISMAGS: graph: Incomplete subgraph: Incomplete - def __init__(self, graph, subgraph, node_match=None, edge_match=None, cache=None) -> None: ... + def __init__( + self, + # Any: graph and subgraph can have unrelated node and data types + graph: Graph[Any, Any, Any], + subgraph: Graph[Any, Any, Any], + node_match=None, + edge_match=None, + cache=None, + ) -> None: ... def create_aligned_partitions(self, thing_matcher, sg_things, g_things): ... def find_isomorphisms(self, symmetry: bool = True) -> Generator[Incomplete, Incomplete, Incomplete]: ... def largest_common_subgraph(self, symmetry: bool = True) -> Generator[Incomplete, Incomplete]: ... diff --git a/stubs/networkx/networkx/algorithms/isomorphism/isomorphvf2.pyi b/stubs/networkx/networkx/algorithms/isomorphism/isomorphvf2.pyi index 734025b38f5e..909cf90fd9a5 100644 --- a/stubs/networkx/networkx/algorithms/isomorphism/isomorphvf2.pyi +++ b/stubs/networkx/networkx/algorithms/isomorphism/isomorphvf2.pyi @@ -1,5 +1,9 @@ from _typeshed import Incomplete from collections.abc import Generator +from typing import Any + +from ...classes.digraph import DiGraph +from ...classes.graph import Graph __all__ = ["GraphMatcher", "DiGraphMatcher"] @@ -12,7 +16,12 @@ class GraphMatcher: old_recursion_limit: Incomplete test: str - def __init__(self, G1, G2) -> None: ... + def __init__( + self, + # Any: G1 and G2 can have unrelated node and data types + G1: Graph[Any, Any, Any], + G2: Graph[Any, Any, Any], + ) -> None: ... def reset_recursion_limit(self) -> None: ... def candidate_pairs_iter(self) -> Generator[Incomplete]: ... core_1: Incomplete @@ -34,7 +43,12 @@ class GraphMatcher: def syntactic_feasibility(self, G1_node, G2_node): ... class DiGraphMatcher(GraphMatcher): - def __init__(self, G1, G2) -> None: ... + def __init__( + self, + # Any: G1 and G2 can have unrelated node and data types + G1: DiGraph[Any, Any, Any], + G2: DiGraph[Any, Any, Any], + ) -> None: ... def candidate_pairs_iter(self) -> Generator[Incomplete]: ... core_1: Incomplete core_2: Incomplete diff --git a/stubs/networkx/networkx/algorithms/isomorphism/matchhelpers.pyi b/stubs/networkx/networkx/algorithms/isomorphism/matchhelpers.pyi index 382cacbd7ec7..6c0335954b09 100644 --- a/stubs/networkx/networkx/algorithms/isomorphism/matchhelpers.pyi +++ b/stubs/networkx/networkx/algorithms/isomorphism/matchhelpers.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete -from collections.abc import Callable, Iterable, Sequence +from collections.abc import Callable, Iterable from types import FunctionType from networkx.utils.backends import _dispatchable @@ -20,38 +20,46 @@ def copyfunc(f, name=None) -> FunctionType: ... def allclose(x, y, rtol: float = 1.0000000000000001e-05, atol: float = 1e-08) -> bool: ... @_dispatchable def categorical_node_match( - attr: str | Iterable[Incomplete], default: Incomplete | Iterable[Incomplete] -) -> Callable[..., Incomplete]: ... - -categorical_edge_match: Incomplete + attr: str | Iterable[str], default: Incomplete | list[Incomplete] +) -> Callable[[Incomplete, Incomplete], bool]: ... +# Same as categorical_node_match, but not dispatchable +def categorical_edge_match( + attr: str | Iterable[str], default: Incomplete | list[Incomplete] +) -> Callable[[Incomplete, Incomplete], bool]: ... @_dispatchable def categorical_multiedge_match( - attr: str | Iterable[Incomplete], default: Incomplete | Iterable[Incomplete] -) -> Callable[..., Incomplete]: ... + attr: str | Iterable[str], default: Incomplete | list[Incomplete] +) -> Callable[[Incomplete, Incomplete], bool]: ... @_dispatchable def numerical_node_match( - attr: str | Iterable[Incomplete], default: Incomplete | Iterable[Incomplete], rtol: float = 1e-05, atol: float = 1e-08 -) -> Callable[..., Incomplete]: ... - -numerical_edge_match: Incomplete + attr: str | Iterable[str], default: Incomplete | list[Incomplete], rtol: float = 1e-05, atol: float = 1e-08 +) -> Callable[[Incomplete, Incomplete], bool]: ... +# Same as numerical_node_match, but not dispatchable +def numerical_edge_match( + attr: str | Iterable[str], default: Incomplete | list[Incomplete], rtol: float = 1e-05, atol: float = 1e-08 +) -> Callable[[Incomplete, Incomplete], bool]: ... @_dispatchable def numerical_multiedge_match( - attr: str | Iterable[Incomplete], default: Incomplete | Iterable[Incomplete], rtol: float = 1e-05, atol: float = 1e-08 -) -> Callable[..., Incomplete]: ... + attr: str | Iterable[str], default: Incomplete | list[Incomplete], rtol: float = 1e-05, atol: float = 1e-08 +) -> Callable[[Incomplete, Incomplete], bool]: ... @_dispatchable def generic_node_match( - attr: str | Iterable[Incomplete], - default: Incomplete | Iterable[Incomplete], - op: Callable[..., Incomplete] | Sequence[Incomplete], -) -> Callable[..., Incomplete]: ... - -generic_edge_match: Incomplete + attr: str | Iterable[str], + default: Incomplete | list[Incomplete], + op: Callable[[Incomplete, Incomplete], Incomplete] | list[Callable[[Incomplete, Incomplete], Incomplete]], +) -> Callable[[Incomplete, Incomplete], bool]: ... +# Same as generic_node_match, but not dispatchable +def generic_edge_match( + attr: str | Iterable[str], + default: Incomplete | list[Incomplete], + op: Callable[[Incomplete, Incomplete], Incomplete] | list[Callable[[Incomplete, Incomplete], Incomplete]], +) -> Callable[[Incomplete, Incomplete], bool]: ... @_dispatchable def generic_multiedge_match( - attr: str | Iterable[Incomplete], - default: Incomplete | Iterable[Incomplete], - op: Callable[..., Incomplete] | Sequence[Incomplete], -) -> Callable[..., Incomplete]: ... + attr: str | Iterable[str], + default: Incomplete | list[Incomplete], + op: Callable[[Incomplete, Incomplete], Incomplete] | list[Callable[[Incomplete, Incomplete], Incomplete]], +) -> Callable[[Incomplete, Incomplete], bool]: ... diff --git a/stubs/networkx/networkx/algorithms/isomorphism/temporalisomorphvf2.pyi b/stubs/networkx/networkx/algorithms/isomorphism/temporalisomorphvf2.pyi index 7ab32a2abcb9..e2be3ab8fd10 100644 --- a/stubs/networkx/networkx/algorithms/isomorphism/temporalisomorphvf2.pyi +++ b/stubs/networkx/networkx/algorithms/isomorphism/temporalisomorphvf2.pyi @@ -1,5 +1,8 @@ from _typeshed import Incomplete +from typing import Any +from ...classes.digraph import DiGraph +from ...classes.graph import Graph from .isomorphvf2 import DiGraphMatcher, GraphMatcher __all__ = ["TimeRespectingGraphMatcher", "TimeRespectingDiGraphMatcher"] @@ -8,7 +11,14 @@ class TimeRespectingGraphMatcher(GraphMatcher): temporal_attribute_name: Incomplete delta: Incomplete - def __init__(self, G1, G2, temporal_attribute_name, delta) -> None: ... + def __init__( + self, + # Any: G1 and G2 can have unrelated node and data types + G1: Graph[Any, Any, Any], + G2: Graph[Any, Any, Any], + temporal_attribute_name, + delta, + ) -> None: ... def one_hop(self, Gx, Gx_node, neighbors): ... def two_hop(self, Gx, core_x, Gx_node, neighbors): ... def semantic_feasibility(self, G1_node, G2_node): ... @@ -17,7 +27,14 @@ class TimeRespectingDiGraphMatcher(DiGraphMatcher): temporal_attribute_name: Incomplete delta: Incomplete - def __init__(self, G1, G2, temporal_attribute_name, delta) -> None: ... + def __init__( + self, + # Any: G1 and G2 can have unrelated node and data types + G1: DiGraph[Any, Any, Any], + G2: DiGraph[Any, Any, Any], + temporal_attribute_name, + delta, + ) -> None: ... def get_pred_dates(self, Gx, Gx_node, core_x, pred): ... def get_succ_dates(self, Gx, Gx_node, core_x, succ): ... def one_hop(self, Gx, Gx_node, core_x, pred, succ): ... diff --git a/stubs/networkx/networkx/algorithms/isomorphism/vf2userfunc.pyi b/stubs/networkx/networkx/algorithms/isomorphism/vf2userfunc.pyi index 475020aa5b05..982bc28b17f7 100644 --- a/stubs/networkx/networkx/algorithms/isomorphism/vf2userfunc.pyi +++ b/stubs/networkx/networkx/algorithms/isomorphism/vf2userfunc.pyi @@ -1,5 +1,9 @@ from _typeshed import Incomplete +from collections.abc import Callable +from typing import Any +from ...classes.digraph import DiGraph +from ...classes.graph import Graph from . import isomorphvf2 as vf2 __all__ = ["GraphMatcher", "DiGraphMatcher", "MultiGraphMatcher", "MultiDiGraphMatcher"] @@ -10,8 +14,15 @@ class GraphMatcher(vf2.GraphMatcher): G1_adj: Incomplete G2_adj: Incomplete - def __init__(self, G1, G2, node_match=None, edge_match=None) -> None: ... - semantic_feasibility: Incomplete + def __init__( + self, + # Any: G1 and G2 can have unrelated node and data types + G1: Graph[Any, Any, Any], + G2: Graph[Any, Any, Any], + node_match: Callable[[Incomplete, Incomplete], object] | None = None, + edge_match: Callable[[Incomplete, Incomplete], object] | None = None, + ) -> None: ... + def semantic_feasibility(self, G1_node, G2_node): ... class DiGraphMatcher(vf2.DiGraphMatcher): node_match: Incomplete @@ -19,7 +30,14 @@ class DiGraphMatcher(vf2.DiGraphMatcher): G1_adj: Incomplete G2_adj: Incomplete - def __init__(self, G1, G2, node_match=None, edge_match=None) -> None: ... + def __init__( + self, + # Any: G1 and G2 can have unrelated node and data types + G1: DiGraph[Any, Any, Any], + G2: DiGraph[Any, Any, Any], + node_match: Callable[[Incomplete, Incomplete], object] | None = None, + edge_match: Callable[[Incomplete, Incomplete], object] | None = None, + ) -> None: ... def semantic_feasibility(self, G1_node, G2_node): ... class MultiGraphMatcher(GraphMatcher): ... diff --git a/stubs/networkx/networkx/algorithms/planarity.pyi b/stubs/networkx/networkx/algorithms/planarity.pyi index 082bfb94007b..e6c01ddfc2d6 100644 --- a/stubs/networkx/networkx/algorithms/planarity.pyi +++ b/stubs/networkx/networkx/algorithms/planarity.pyi @@ -73,7 +73,7 @@ class LRPlanarity: lowpt_edge: Incomplete left_ref: Incomplete right_ref: Incomplete - embedding: Incomplete + embedding: PlanarEmbedding[Incomplete] def __init__(self, G: Graph[_Node]) -> None: ... def lr_planarity(self) -> PlanarEmbedding[Incomplete] | None: ... diff --git a/stubs/networkx/networkx/algorithms/tournament.pyi b/stubs/networkx/networkx/algorithms/tournament.pyi index 0fff43290acb..a9d7005fecd2 100644 --- a/stubs/networkx/networkx/algorithms/tournament.pyi +++ b/stubs/networkx/networkx/algorithms/tournament.pyi @@ -1,10 +1,14 @@ from _typeshed import Incomplete +from collections.abc import Callable, Iterable +from typing import TypeVar from networkx.classes.digraph import DiGraph from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable from numpy.random import RandomState +_T = TypeVar("_T") + __all__ = [ "hamiltonian_path", "is_reachable", @@ -15,6 +19,7 @@ __all__ = [ "tournament_matrix", ] +def index_satisfying(iterable: Iterable[_T], condition: Callable[[_T], object]) -> int: ... @_dispatchable def is_tournament(G: Graph[_Node]) -> bool: ... @_dispatchable diff --git a/stubs/networkx/networkx/algorithms/tree/branchings.pyi b/stubs/networkx/networkx/algorithms/tree/branchings.pyi index c9444c109a8d..2a00a178baa0 100644 --- a/stubs/networkx/networkx/algorithms/tree/branchings.pyi +++ b/stubs/networkx/networkx/algorithms/tree/branchings.pyi @@ -1,4 +1,5 @@ from _typeshed import Incomplete +from collections.abc import Iterable, Sequence from dataclasses import dataclass from typing import Final from typing_extensions import Self @@ -65,7 +66,13 @@ class ArborescenceIterator: partition_key: str init_partition: Incomplete - def __init__(self, G: DiGraph[_Node], weight: str = "weight", minimum: bool = True, init_partition=None) -> None: ... + def __init__( + self, + G: DiGraph[_Node], + weight: str = "weight", + minimum: bool = True, + init_partition: Sequence[Iterable[Incomplete]] | None = None, + ) -> None: ... partition_queue: Incomplete def __iter__(self) -> Self: ... diff --git a/stubs/networkx/networkx/algorithms/tree/coding.pyi b/stubs/networkx/networkx/algorithms/tree/coding.pyi index 7e6013a8526e..79ef15db9528 100644 --- a/stubs/networkx/networkx/algorithms/tree/coding.pyi +++ b/stubs/networkx/networkx/algorithms/tree/coding.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete -from collections.abc import Iterable +from collections.abc import Collection from networkx.classes.graph import Graph, _Node from networkx.exception import NetworkXException @@ -12,8 +12,8 @@ class NotATree(NetworkXException): ... @_dispatchable def to_nested_tuple(T: Graph[_Node], root: _Node, canonical_form: bool = False) -> tuple[Incomplete, ...]: ... @_dispatchable -def from_nested_tuple(sequence: tuple[Incomplete, ...], sensible_relabeling: bool = False) -> Graph[Incomplete]: ... +def from_nested_tuple(sequence: Collection[Incomplete], sensible_relabeling: bool = False) -> Graph[Incomplete]: ... @_dispatchable def to_prufer_sequence(T: Graph[_Node]) -> list[Incomplete]: ... @_dispatchable -def from_prufer_sequence(sequence: Iterable[Incomplete]) -> Graph[Incomplete]: ... +def from_prufer_sequence(sequence: Collection[Incomplete]) -> Graph[Incomplete]: ... diff --git a/stubs/networkx/networkx/algorithms/tree/decomposition.pyi b/stubs/networkx/networkx/algorithms/tree/decomposition.pyi index f50ed7b684fc..1b003acef2dc 100644 --- a/stubs/networkx/networkx/algorithms/tree/decomposition.pyi +++ b/stubs/networkx/networkx/algorithms/tree/decomposition.pyi @@ -1,9 +1,7 @@ -from _typeshed import Incomplete - from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable __all__ = ["junction_tree"] @_dispatchable -def junction_tree(G: Graph[_Node]) -> Graph[Incomplete]: ... +def junction_tree(G: Graph[_Node]) -> Graph[tuple[_Node, ...]]: ... diff --git a/stubs/networkx/networkx/algorithms/voronoi.pyi b/stubs/networkx/networkx/algorithms/voronoi.pyi index 63f890bf2591..1abe370f2087 100644 --- a/stubs/networkx/networkx/algorithms/voronoi.pyi +++ b/stubs/networkx/networkx/algorithms/voronoi.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete, SupportsGetItem -from collections.abc import Callable +from collections.abc import Callable, Collection from typing import Any from networkx.classes.graph import Graph, _Node @@ -10,6 +10,6 @@ __all__ = ["voronoi_cells"] @_dispatchable def voronoi_cells( G: Graph[_Node], - center_nodes: set[Incomplete], + center_nodes: Collection[Incomplete], weight: str | Callable[[Any, Any, SupportsGetItem[str, Any]], float | None] | None = "weight", ) -> dict[Incomplete, set[Incomplete]]: ... diff --git a/stubs/networkx/networkx/classes/function.pyi b/stubs/networkx/networkx/classes/function.pyi index 8ac27209e6a0..53d387dadb3c 100644 --- a/stubs/networkx/networkx/classes/function.pyi +++ b/stubs/networkx/networkx/classes/function.pyi @@ -74,10 +74,14 @@ def is_frozen(G: Graph[Incomplete]) -> bool: ... def add_star(G_to_add_to: Graph[Incomplete], nodes_for_star: Iterable[Incomplete], **attr) -> None: ... def add_path(G_to_add_to: Graph[Incomplete], nodes_for_path: Iterable[Incomplete], **attr) -> None: ... def add_cycle(G_to_add_to: Graph[Incomplete], nodes_for_cycle: Iterable[Incomplete], **attr) -> None: ... -def subgraph(G: Graph[_Node], nbunch: Iterable[Incomplete]): ... +def subgraph(G: Graph[_Node], nbunch: _NBunch[_Node]): ... def induced_subgraph(G: Graph[_Node, _NodeData, _EdgeData], nbunch: _NBunch[_Node]) -> Graph[_Node, _NodeData, _EdgeData]: ... -def edge_subgraph(G: Graph[_Node], edges: Iterable[Incomplete]) -> Graph[Incomplete]: ... -def restricted_view(G: Graph[_Node], nodes: Iterable[Incomplete], edges: Iterable[Incomplete]) -> Graph[Incomplete]: ... +def edge_subgraph(G: Graph[_Node, _NodeData, _EdgeData], edges: Iterable[Incomplete]) -> Graph[_Node, _NodeData, _EdgeData]: ... +def restricted_view( + G: Graph[_Node, _NodeData, _EdgeData], + nodes: Iterable[Incomplete], + edges: Collection[Incomplete], # Not Iterable: iterated more than once, one-shot iterables give wrong results +) -> Graph[_Node, _NodeData, _EdgeData]: ... def to_directed(graph): ... def to_undirected(graph): ... def create_empty_copy(G: Graph[_Node], with_data: bool = True): ... @@ -176,5 +180,9 @@ def selfloop_edges( @_dispatchable def number_of_selfloops(G: Graph[_Node]) -> int: ... def is_path(G: Graph[_Node], path: Iterable[Incomplete]) -> bool: ... -def path_weight(G: Graph[_Node], path: Collection[Incomplete], weight: str) -> int: ... +def path_weight( + G: Graph[_Node], + path: Collection[Incomplete], # Not Iterable: iterated more than once, one-shot iterables give wrong results + weight: str, +) -> float: ... def describe(G: Graph[_Node], describe_hook: Callable[[Graph[_Node]], dict[str, Incomplete]] | None = None) -> None: ... diff --git a/stubs/networkx/networkx/classes/reportviews.pyi b/stubs/networkx/networkx/classes/reportviews.pyi index 5bf0396d6108..0e5b684117d2 100644 --- a/stubs/networkx/networkx/classes/reportviews.pyi +++ b/stubs/networkx/networkx/classes/reportviews.pyi @@ -234,7 +234,11 @@ class OutMultiEdgeView(OutEdgeView[_Node, _NodeData, _EdgeData]): __slots__ = () def __iter__(self) -> Iterator[tuple[_Node, _Node, Incomplete]]: ... # type: ignore[override] def __getitem__(self, e: tuple[_Node, _Node, Incomplete]) -> _EdgeData: ... # type: ignore[override] - dataview = OutMultiEdgeDataView + dataview: type[ # Including subtypes' possible return types for LSP + OutMultiEdgeDataView[Incomplete, Incomplete] + | MultiEdgeDataView[Incomplete, Incomplete] + | InMultiEdgeDataView[Incomplete, Incomplete] + ] @overload # type: ignore[override] # Has an additional `keys` keyword argument def __call__( # type: ignore[overload-overlap] diff --git a/stubs/networkx/networkx/convert.pyi b/stubs/networkx/networkx/convert.pyi index b6bd41f09185..74e5885e7aa3 100644 --- a/stubs/networkx/networkx/convert.pyi +++ b/stubs/networkx/networkx/convert.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete -from collections.abc import Callable, Collection, Iterable +from collections.abc import Callable, Collection, Iterable, Mapping from networkx.classes.graph import Graph, _Data, _EdgeData, _Node, _NodeData from networkx.utils.backends import _dispatchable @@ -30,7 +30,7 @@ def to_dict_of_dicts( ) -> dict[Incomplete, Incomplete]: ... @_dispatchable def from_dict_of_dicts( - d: dict[Incomplete, Incomplete], + d: Mapping[Incomplete, Mapping[Incomplete, Incomplete]], create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None, multigraph_input: bool = False, ) -> Graph[Incomplete]: ... diff --git a/stubs/networkx/networkx/generators/classic.pyi b/stubs/networkx/networkx/generators/classic.pyi index f84af8a5d1ae..8b17fcceaac4 100644 --- a/stubs/networkx/networkx/generators/classic.pyi +++ b/stubs/networkx/networkx/generators/classic.pyi @@ -1,7 +1,7 @@ from _typeshed import Incomplete -from collections.abc import Iterable +from collections.abc import Callable, Iterable -from networkx.classes import Graph +from networkx.classes.graph import Graph from networkx.utils.backends import _dispatchable __all__ = [ @@ -60,9 +60,9 @@ def dorogovtsev_goltsev_mendes_graph( ) -> Graph[Incomplete]: ... @_dispatchable def empty_graph( - n: Incomplete | int = 0, + n: int | Iterable[Incomplete] = 0, create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None, - default: type[Graph[Incomplete]] = ..., + default: Callable[[], Graph[Incomplete]] = ..., ): ... @_dispatchable def ladder_graph(n, create_using=None): ... diff --git a/stubs/networkx/networkx/generators/cographs.pyi b/stubs/networkx/networkx/generators/cographs.pyi index 53238e9fe20a..6653c11beb78 100644 --- a/stubs/networkx/networkx/generators/cographs.pyi +++ b/stubs/networkx/networkx/generators/cographs.pyi @@ -1,9 +1,7 @@ -from _typeshed import Incomplete - from networkx.classes.graph import Graph from networkx.utils.backends import _dispatchable __all__ = ["random_cograph"] @_dispatchable -def random_cograph(n: int, seed=None) -> Graph[Incomplete]: ... +def random_cograph(n: int, seed=None) -> Graph[int]: ... diff --git a/stubs/networkx/networkx/generators/community.pyi b/stubs/networkx/networkx/generators/community.pyi index 8a3102cc5154..0161d7ad7d7d 100644 --- a/stubs/networkx/networkx/generators/community.pyi +++ b/stubs/networkx/networkx/generators/community.pyi @@ -1,8 +1,8 @@ -from _typeshed import Incomplete -from collections.abc import Collection +from collections.abc import Sequence +from typing import Literal, overload from networkx.classes.digraph import DiGraph -from networkx.classes.graph import Graph +from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable __all__ = [ @@ -24,32 +24,127 @@ def caveman_graph(l: int, k: int) -> Graph[int]: ... def connected_caveman_graph(l: int, k: int) -> Graph[int]: ... @_dispatchable def relaxed_caveman_graph(l: int, k: int, p: float, seed=None) -> Graph[int]: ... -@_dispatchable + +# @_dispatchable adds the backend arguments, but we can't use this decorator with @overload +@overload def random_partition_graph( - sizes: list[int], p_in: float, p_out: float, seed=None, directed: bool = False -) -> DiGraph[Incomplete]: ... -@_dispatchable + sizes: Sequence[int], p_in: float, p_out: float, seed=None, *, directed: Literal[True], backend=None, **backend_kwargs +) -> DiGraph[int]: ... +@overload +def random_partition_graph( + sizes: Sequence[int], p_in: float, p_out: float, seed, directed: Literal[True], *, backend=None, **backend_kwargs +) -> DiGraph[int]: ... +@overload +def random_partition_graph( + sizes: Sequence[int], p_in: float, p_out: float, seed=None, directed: bool = False, *, backend=None, **backend_kwargs +) -> Graph[int]: ... + +@overload def planted_partition_graph( - l: int, k: int, p_in: float, p_out: float, seed=None, directed: bool = False -) -> DiGraph[Incomplete]: ... -@_dispatchable + l: int, k: int, p_in: float, p_out: float, seed=None, *, directed: Literal[True], backend=None, **backend_kwargs +) -> DiGraph[int]: ... +@overload +def planted_partition_graph( + l: int, k: int, p_in: float, p_out: float, seed, directed: Literal[True], *, backend=None, **backend_kwargs +) -> DiGraph[int]: ... +@overload +def planted_partition_graph( + l: int, k: int, p_in: float, p_out: float, seed=None, directed: bool = False, *, backend=None, **backend_kwargs +) -> Graph[int]: ... + +@overload +def gaussian_random_partition_graph( + n: int, s: float, v: float, p_in: float, p_out: float, directed: Literal[True], seed=None, *, backend=None, **backend_kwargs +) -> DiGraph[int]: ... +@overload def gaussian_random_partition_graph( - n: int, s: float, v: float, p_in: float, p_out: float, directed: bool = False, seed=None -) -> DiGraph[Incomplete]: ... + n: int, s: float, v: float, p_in: float, p_out: float, directed: bool = False, seed=None, *, backend=None, **backend_kwargs +) -> Graph[int]: ... + @_dispatchable def ring_of_cliques(num_cliques: int, clique_size: int) -> Graph[int]: ... @_dispatchable def windmill_graph(n: int, k: int) -> Graph[int]: ... -@_dispatchable + +@overload +def stochastic_block_model( + sizes: Sequence[int], + p: Sequence[Sequence[float]], + nodelist: None = None, + seed=None, + *, + directed: Literal[True], + selfloops: bool = False, + sparse: bool = True, + backend=None, + **backend_kwargs, +) -> DiGraph[int]: ... +@overload +def stochastic_block_model( + sizes: Sequence[int], + p: Sequence[Sequence[float]], + nodelist: None, + seed, + directed: Literal[True], + selfloops: bool = False, + sparse: bool = True, + *, + backend=None, + **backend_kwargs, +) -> DiGraph[int]: ... +@overload def stochastic_block_model( - sizes: list[int], - p: list[list[float]], - nodelist: Collection[Incomplete] | None = None, + sizes: Sequence[int], + p: Sequence[Sequence[float]], + nodelist: Sequence[_Node], + seed=None, + *, + directed: Literal[True], + selfloops: bool = False, + sparse: bool = True, + backend=None, + **backend_kwargs, +) -> DiGraph[_Node]: ... +@overload +def stochastic_block_model( + sizes: Sequence[int], + p: Sequence[Sequence[float]], + nodelist: Sequence[_Node], + seed, + directed: Literal[True], + selfloops: bool = False, + sparse: bool = True, + *, + backend=None, + **backend_kwargs, +) -> DiGraph[_Node]: ... +@overload +def stochastic_block_model( + sizes: Sequence[int], + p: Sequence[Sequence[float]], + nodelist: None = None, seed=None, directed: bool = False, selfloops: bool = False, sparse: bool = True, -) -> DiGraph[Incomplete]: ... + *, + backend=None, + **backend_kwargs, +) -> Graph[int]: ... +@overload +def stochastic_block_model( + sizes: Sequence[int], + p: Sequence[Sequence[float]], + nodelist: Sequence[_Node], + seed=None, + directed: bool = False, + selfloops: bool = False, + sparse: bool = True, + *, + backend=None, + **backend_kwargs, +) -> Graph[_Node]: ... + @_dispatchable def LFR_benchmark_graph( n: int, diff --git a/stubs/networkx/networkx/generators/degree_seq.pyi b/stubs/networkx/networkx/generators/degree_seq.pyi index 562806bed693..7c4ddca80144 100644 --- a/stubs/networkx/networkx/generators/degree_seq.pyi +++ b/stubs/networkx/networkx/generators/degree_seq.pyi @@ -1,4 +1,5 @@ from _typeshed import Incomplete +from collections.abc import Collection from networkx.utils.backends import _dispatchable @@ -29,7 +30,7 @@ def directed_configuration_model( seed=None, ) -> MultiDiGraph[Incomplete]: ... @_dispatchable -def expected_degree_graph(w: list[Incomplete], seed=None, selfloops: bool = True) -> Graph[Incomplete]: ... +def expected_degree_graph(w: Collection[float], seed=None, selfloops: bool = True) -> Graph[int]: ... @_dispatchable def havel_hakimi_graph(deg_sequence: list[int], create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None): ... @_dispatchable diff --git a/stubs/networkx/networkx/generators/directed.pyi b/stubs/networkx/networkx/generators/directed.pyi index 0d32d803d860..3b068d624a91 100644 --- a/stubs/networkx/networkx/generators/directed.pyi +++ b/stubs/networkx/networkx/generators/directed.pyi @@ -11,7 +11,10 @@ __all__ = ["gn_graph", "gnc_graph", "gnr_graph", "random_k_out_graph", "scale_fr @_dispatchable def gn_graph( - n: int, kernel: Callable[..., Incomplete] | None = None, create_using: DiGraph[Incomplete] | None = None, seed=None + n: int, + kernel: Callable[[int], float] | None = None, + create_using: DiGraph[Incomplete] | type[DiGraph[Incomplete]] | None = None, + seed=None, ): ... @_dispatchable def gnr_graph(n: int, p: float, create_using: DiGraph[Incomplete] | type[DiGraph[Incomplete]] | None = None, seed=None): ... diff --git a/stubs/networkx/networkx/generators/geometric.pyi b/stubs/networkx/networkx/generators/geometric.pyi index 1d12fb9c17be..22d1da0666ef 100644 --- a/stubs/networkx/networkx/generators/geometric.pyi +++ b/stubs/networkx/networkx/generators/geometric.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete -from collections.abc import Callable, Iterable +from collections.abc import Callable, Iterable, Mapping from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable @@ -22,7 +22,7 @@ def random_geometric_graph( n: int | Iterable[Incomplete], radius: float, dim: int = 2, - pos: dict[Incomplete, Incomplete] | None = None, + pos: Mapping[Incomplete, Incomplete] | None = None, p: float = 2, seed=None, ) -> Graph[Incomplete]: ... @@ -31,9 +31,9 @@ def soft_random_geometric_graph( n: int | Iterable[Incomplete], radius: float, dim: int = 2, - pos: dict[Incomplete, Incomplete] | None = None, + pos: Mapping[Incomplete, Incomplete] | None = None, p: float = 2, - p_dist: Callable[..., Incomplete] | None = None, + p_dist: Callable[[float], float] | None = None, seed=None, ) -> Graph[Incomplete]: ... @_dispatchable @@ -41,10 +41,10 @@ def geographical_threshold_graph( n: int | Iterable[Incomplete], theta: float, dim: int = 2, - pos: dict[Incomplete, Incomplete] | None = None, - weight: dict[Incomplete, Incomplete] | None = None, - metric: Callable[..., Incomplete] | None = None, - p_dist: Callable[..., Incomplete] | None = None, + pos: Mapping[Incomplete, Incomplete] | None = None, + weight: Mapping[Incomplete, float] | None = None, + metric: Callable[[Incomplete, Incomplete], float] | None = None, + p_dist: Callable[[float], float] | None = None, seed=None, ) -> Graph[Incomplete]: ... @_dispatchable diff --git a/stubs/networkx/networkx/generators/intersection.pyi b/stubs/networkx/networkx/generators/intersection.pyi index b631d2b1e31c..2a6d4a18c667 100644 --- a/stubs/networkx/networkx/generators/intersection.pyi +++ b/stubs/networkx/networkx/generators/intersection.pyi @@ -1,3 +1,5 @@ +from collections.abc import Collection + from networkx.utils.backends import _dispatchable __all__ = ["uniform_random_intersection_graph", "k_random_intersection_graph", "general_random_intersection_graph"] @@ -7,4 +9,4 @@ def uniform_random_intersection_graph(n: int, m: int, p: float, seed=None): ... @_dispatchable def k_random_intersection_graph(n: int, m: int, k: float, seed=None): ... @_dispatchable -def general_random_intersection_graph(n: int, m: int, p: list[float], seed=None): ... +def general_random_intersection_graph(n: int, m: int, p: Collection[float], seed=None): ... diff --git a/stubs/networkx/networkx/generators/lattice.pyi b/stubs/networkx/networkx/generators/lattice.pyi index 1b365e7815b3..ed68f41c1b51 100644 --- a/stubs/networkx/networkx/generators/lattice.pyi +++ b/stubs/networkx/networkx/generators/lattice.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete -from collections.abc import Iterable +from collections.abc import Iterable, Sequence from networkx.classes.graph import Graph from networkx.utils.backends import _dispatchable @@ -8,10 +8,13 @@ __all__ = ["grid_2d_graph", "grid_graph", "hypercube_graph", "triangular_lattice @_dispatchable def grid_2d_graph( - m, n, periodic: bool = False, create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None + m: int | Iterable[Incomplete], + n: int | Iterable[Incomplete], + periodic: bool | Iterable[bool] = False, + create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None, ) -> Graph[Incomplete]: ... @_dispatchable -def grid_graph(dim: list[float] | tuple[float, ...] | Iterable[Incomplete], periodic: bool = False) -> Graph[Incomplete]: ... +def grid_graph(dim: Sequence[int | Iterable[Incomplete]], periodic: bool | Iterable[bool] = False) -> Graph[Incomplete]: ... @_dispatchable def hypercube_graph(n: int) -> Graph[Incomplete]: ... @_dispatchable diff --git a/stubs/networkx/networkx/generators/random_graphs.pyi b/stubs/networkx/networkx/generators/random_graphs.pyi index d9e1d6c05571..419ce2bbdf7d 100644 --- a/stubs/networkx/networkx/generators/random_graphs.pyi +++ b/stubs/networkx/networkx/generators/random_graphs.pyi @@ -65,7 +65,7 @@ def powerlaw_cluster_graph(n: int, m: int, p: float, seed=None, *, create_using= def random_lobster_graph(n: int, p1: float, p2: float, seed=None, *, create_using=None): ... @_dispatchable @deprecated("`random_lobster` is a deprecated alias for `random_lobster_graph`. Use `random_lobster_graph` instead.") -def random_lobster(n, p1, p2, seed=None, *, create_using=None): ... +def random_lobster(n: int, p1: float, p2: float, seed=None, *, create_using=None): ... @_dispatchable def random_shell_graph(constructor: Iterable[tuple[int, int, float]], seed=None, *, create_using=None): ... @_dispatchable @@ -75,8 +75,8 @@ def random_powerlaw_tree_sequence(n: int, gamma: float = 3, seed=None, tries: in @_dispatchable def random_kernel_graph( n: int, - kernel_integral: Callable[..., Incomplete], - kernel_root: Callable[..., Incomplete] | None = None, + kernel_integral: Callable[[float, float, float], float], + kernel_root: Callable[[float, float, float], float] | None = None, seed=None, *, create_using=None, diff --git a/stubs/networkx/networkx/generators/spectral_graph_forge.pyi b/stubs/networkx/networkx/generators/spectral_graph_forge.pyi index 2822fc3544a7..7fe18567cad4 100644 --- a/stubs/networkx/networkx/generators/spectral_graph_forge.pyi +++ b/stubs/networkx/networkx/generators/spectral_graph_forge.pyi @@ -1,9 +1,7 @@ -from _typeshed import Incomplete - from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable __all__ = ["spectral_graph_forge"] @_dispatchable -def spectral_graph_forge(G: Graph[_Node], alpha: float, transformation: str = "identity", seed=None) -> Graph[Incomplete]: ... +def spectral_graph_forge(G: Graph[_Node], alpha: float, transformation: str = "identity", seed=None) -> Graph[int]: ... diff --git a/stubs/networkx/networkx/lazy_imports.pyi b/stubs/networkx/networkx/lazy_imports.pyi index f806469927aa..add2221c6cfe 100644 --- a/stubs/networkx/networkx/lazy_imports.pyi +++ b/stubs/networkx/networkx/lazy_imports.pyi @@ -1,11 +1,12 @@ import types from _typeshed import Incomplete +from collections.abc import Callable, Iterable, Mapping __all__ = ["attach", "_lazy_import"] def attach( - module_name: str, submodules: set[Incomplete] | None = None, submod_attrs: dict[Incomplete, Incomplete] | None = None -): ... + module_name: str, submodules: Iterable[str] | None = None, submod_attrs: Mapping[str, Iterable[str]] | None = None +) -> tuple[Callable[[str], Incomplete], Callable[[], list[str]], list[str]]: ... class DelayedImportErrorModule(types.ModuleType): def __init__(self, frame_data, *args, **kwargs) -> None: ... diff --git a/stubs/networkx/networkx/linalg/attrmatrix.pyi b/stubs/networkx/networkx/linalg/attrmatrix.pyi index 90b19c231e4d..5163c149e35a 100644 --- a/stubs/networkx/networkx/linalg/attrmatrix.pyi +++ b/stubs/networkx/networkx/linalg/attrmatrix.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete -from collections.abc import Collection +from collections.abc import Callable, Collection, Hashable from typing import Any, Literal from networkx._typing import Array2D @@ -13,9 +13,9 @@ __all__ = ["attr_matrix", "attr_sparse_matrix"] @_dispatchable def attr_matrix( G: Graph[_Node], - edge_attr: str | None = None, - node_attr: str | None = None, # runtime also accepts `Callable[[_Node], object]`, but it is not documented - normalized: bool = False, # runtime also accepts `Callable[[_Node, _Node], object]`, but it is not documented + edge_attr: str | Callable[[_Node, _Node], Incomplete] | None = None, # Callable: Not documented + node_attr: str | Callable[[_Node], Hashable] | None = None, # Callable: Not documented + normalized: bool = False, rc_order: Collection[_Node] | None = None, dtype: DTypeLike | None = None, order: Literal["C", "F"] | None = None, @@ -28,9 +28,9 @@ def attr_matrix( @_dispatchable def attr_sparse_matrix( G: Graph[_Node], - edge_attr: str | None = None, - node_attr: str | None = None, # runtime also accepts `Callable[[_Node], object]`, but it is not documented - normalized: bool = False, # runtime also accepts `Callable[[_Node, _Node], object]`, but it is not documented + edge_attr: str | Callable[[_Node, _Node], Incomplete] | None = None, # Callable: Not documented + node_attr: str | Callable[[_Node], Hashable] | None = None, # Callable: Not documented + normalized: bool = False, rc_order: Collection[_Node] | None = None, dtype: DTypeLike | None = None, # TODO: overload on rc_order and node_attr diff --git a/stubs/networkx/networkx/readwrite/adjlist.pyi b/stubs/networkx/networkx/readwrite/adjlist.pyi index f416e8f891f4..15db3ba2ea9d 100644 --- a/stubs/networkx/networkx/readwrite/adjlist.pyi +++ b/stubs/networkx/networkx/readwrite/adjlist.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete, StrPath, SupportsRead, SupportsWrite -from collections.abc import Generator, Iterable +from collections.abc import Callable, Generator, Iterable from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable @@ -16,7 +16,7 @@ def parse_adjlist( comments: str = "#", delimiter: str | None = None, create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None, - nodetype: type[Incomplete] | None = None, + nodetype: Callable[[str], Incomplete] | None = None, ) -> Graph[Incomplete]: ... @_dispatchable def read_adjlist( @@ -24,6 +24,6 @@ def read_adjlist( comments: str = "#", delimiter: str | None = None, create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None, - nodetype: type[Incomplete] | None = None, + nodetype: Callable[[str], Incomplete] | None = None, encoding: str = "utf-8", ) -> Graph[Incomplete]: ... diff --git a/stubs/networkx/networkx/readwrite/edgelist.pyi b/stubs/networkx/networkx/readwrite/edgelist.pyi index 8c2983fc3efc..c5ed0982c06b 100644 --- a/stubs/networkx/networkx/readwrite/edgelist.pyi +++ b/stubs/networkx/networkx/readwrite/edgelist.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete, StrPath, SupportsRead, SupportsWrite -from collections.abc import Generator, Iterable +from collections.abc import Callable, Collection, Generator, Iterable from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable @@ -13,32 +13,36 @@ __all__ = [ "write_weighted_edgelist", ] -def generate_edgelist(G: Graph[_Node], delimiter: str = " ", data: bool = True) -> Generator[Incomplete]: ... +def generate_edgelist( + G: Graph[_Node], + delimiter: str = " ", + data: bool | Collection[Incomplete] = True, # Not Iterable: iterated more than once, one-shot iterables give wrong results +) -> Generator[str]: ... def write_edgelist( G: Graph[_Node], path: StrPath | SupportsWrite[bytes], comments: str = "#", delimiter: str = " ", - data: bool = True, + data: bool | Collection[Incomplete] = True, # Not Iterable: iterated more than once, one-shot iterables give wrong results encoding: str = "utf-8", ) -> None: ... @_dispatchable def parse_edgelist( lines: Iterable[str], - comments: str = "#", + comments: str | None = "#", delimiter: str | None = None, create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None, - nodetype: type[Incomplete] | None = None, - data: bool = True, + nodetype: Callable[[str], Incomplete] | None = None, + data: bool | Collection[tuple[str, Callable[[str], Incomplete]]] = True, ) -> Graph[Incomplete]: ... @_dispatchable def read_edgelist( path: StrPath | SupportsRead[bytes], - comments: str = "#", + comments: str | None = "#", delimiter: str | None = None, create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None, - nodetype=None, - data: bool = True, + nodetype: Callable[[str], Incomplete] | None = None, + data: bool | Collection[tuple[str, Callable[[str], Incomplete]]] = True, edgetype=None, encoding: str = "utf-8", ) -> Graph[Incomplete]: ... @@ -48,9 +52,9 @@ def write_weighted_edgelist( @_dispatchable def read_weighted_edgelist( path: StrPath | SupportsRead[bytes], - comments: str = "#", + comments: str | None = "#", delimiter: str | None = None, create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None, - nodetype=None, + nodetype: Callable[[str], Incomplete] | None = None, encoding: str = "utf-8", ) -> Graph[Incomplete]: ... diff --git a/stubs/networkx/networkx/readwrite/gexf.pyi b/stubs/networkx/networkx/readwrite/gexf.pyi index bebb998dfe93..7e5e90f270ca 100644 --- a/stubs/networkx/networkx/readwrite/gexf.pyi +++ b/stubs/networkx/networkx/readwrite/gexf.pyi @@ -26,7 +26,7 @@ def read_gexf( ) -> Graph[Incomplete]: ... class GEXF: - versions: Incomplete + versions: dict[str, dict[str, str]] xml_type: Incomplete python_type: Incomplete def construct_types(self) -> None: ... diff --git a/stubs/networkx/networkx/readwrite/gml.pyi b/stubs/networkx/networkx/readwrite/gml.pyi index 3a9e321d4edf..a239dde83117 100644 --- a/stubs/networkx/networkx/readwrite/gml.pyi +++ b/stubs/networkx/networkx/readwrite/gml.pyi @@ -15,11 +15,11 @@ def unescape(text): ... def literal_destringizer(rep: str): ... @_dispatchable def read_gml( - path: StrPath | SupportsRead[bytes], label: str = "label", destringizer: Callable[..., Incomplete] | None = None + path: StrPath | SupportsRead[bytes], label: str = "label", destringizer: Callable[[Incomplete], Incomplete] | None = None ) -> Graph[Incomplete]: ... @_dispatchable def parse_gml( - lines: str | Iterable[str], label: str = "label", destringizer: Callable[..., Incomplete] | None = None + lines: str | Iterable[str], label: str = "label", destringizer: Callable[[Incomplete], Incomplete] | None = None ) -> Graph[Incomplete]: ... class Pattern(Enum): @@ -41,7 +41,7 @@ LIST_START_VALUE: Final = "_networkx_list_start" def parse_gml_lines(lines, label, destringizer): ... def literal_stringizer(value) -> str: ... -def generate_gml(G: Graph[_Node], stringizer: Callable[..., Incomplete] | None = None) -> Generator[Incomplete, Incomplete]: ... +def generate_gml(G: Graph[_Node], stringizer: Callable[[Incomplete], str] | None = None) -> Generator[str]: ... def write_gml( - G: Graph[_Node], path: StrPath | SupportsWrite[bytes], stringizer: Callable[..., Incomplete] | None = None + G: Graph[_Node], path: StrPath | SupportsWrite[bytes], stringizer: Callable[[Incomplete], str] | None = None ) -> None: ... diff --git a/stubs/networkx/networkx/readwrite/graph6.pyi b/stubs/networkx/networkx/readwrite/graph6.pyi index 17cd91d94b58..8a0eaa8a46a8 100644 --- a/stubs/networkx/networkx/readwrite/graph6.pyi +++ b/stubs/networkx/networkx/readwrite/graph6.pyi @@ -1,19 +1,18 @@ -from _typeshed import Incomplete, StrPath, SupportsRead, SupportsWrite -from collections.abc import Iterable +from _typeshed import StrPath, SupportsRead, SupportsWrite -from networkx.classes.graph import Graph, _Node +from networkx.classes.graph import Graph, _NBunch, _Node from networkx.utils.backends import _dispatchable __all__ = ["from_graph6_bytes", "read_graph6", "to_graph6_bytes", "write_graph6"] @_dispatchable -def from_graph6_bytes(bytes_in: bytes) -> Graph[Incomplete]: ... -def to_graph6_bytes(G: Graph[_Node], nodes: Iterable[Incomplete] | None = None, header: bool = True): ... +def from_graph6_bytes(bytes_in: bytes | bytearray) -> Graph[int]: ... +def to_graph6_bytes(G: Graph[_Node], nodes: _NBunch[_Node] = None, header: bool = True) -> bytes: ... @_dispatchable -def read_graph6(path: StrPath | SupportsRead[bytes]) -> Graph[Incomplete]: ... +def read_graph6(path: StrPath | SupportsRead[bytes]): ... # Returns a Graph or a list of Graphs depending on the file's content def write_graph6( - G: Graph[_Node], path: StrPath | SupportsWrite[bytes], nodes: Iterable[Incomplete] | None = None, header: bool = True -): ... -def write_graph6_file(G: Graph[_Node], f, nodes: Iterable[Incomplete] | None = None, header: bool = True): ... + G: Graph[_Node], path: StrPath | SupportsWrite[bytes], nodes: _NBunch[_Node] = None, header: bool = True +) -> None: ... +def write_graph6_file(G: Graph[_Node], f: SupportsWrite[bytes], nodes: _NBunch[_Node] = None, header: bool = True) -> None: ... def data_to_n(data): ... def n_to_data(n): ... diff --git a/stubs/networkx/networkx/readwrite/json_graph/adjacency.pyi b/stubs/networkx/networkx/readwrite/json_graph/adjacency.pyi index e1728b1cc49f..0f733b045cee 100644 --- a/stubs/networkx/networkx/readwrite/json_graph/adjacency.pyi +++ b/stubs/networkx/networkx/readwrite/json_graph/adjacency.pyi @@ -1,4 +1,5 @@ from _typeshed import Incomplete +from collections.abc import Mapping from typing import Any from networkx.classes.graph import Graph, _Node @@ -7,11 +8,11 @@ from networkx.utils.backends import _dispatchable __all__ = ["adjacency_data", "adjacency_graph"] # Any: Complex type union -def adjacency_data(G: Graph[_Node], attrs: dict[Incomplete, Incomplete] = {"id": "id", "key": "key"}) -> dict[str, Any]: ... +def adjacency_data(G: Graph[_Node], attrs: Mapping[str, Incomplete] = {"id": "id", "key": "key"}) -> dict[str, Any]: ... @_dispatchable def adjacency_graph( - data: dict[Incomplete, Incomplete], + data: Mapping[str, Incomplete], directed: bool = False, multigraph: bool = True, - attrs: dict[Incomplete, Incomplete] = {"id": "id", "key": "key"}, + attrs: Mapping[str, Incomplete] = {"id": "id", "key": "key"}, ) -> Graph[Incomplete]: ... diff --git a/stubs/networkx/networkx/readwrite/json_graph/cytoscape.pyi b/stubs/networkx/networkx/readwrite/json_graph/cytoscape.pyi index 959ffb3b2ed5..344f8e41d039 100644 --- a/stubs/networkx/networkx/readwrite/json_graph/cytoscape.pyi +++ b/stubs/networkx/networkx/readwrite/json_graph/cytoscape.pyi @@ -1,4 +1,5 @@ from _typeshed import Incomplete +from collections.abc import Mapping from typing import Any from networkx.classes.graph import Graph, _Node @@ -9,4 +10,4 @@ __all__ = ["cytoscape_data", "cytoscape_graph"] # Any: Complex type union def cytoscape_data(G: Graph[_Node], name: str = "name", ident: str = "id") -> dict[str, Any]: ... @_dispatchable -def cytoscape_graph(data: dict[Incomplete, Incomplete], name: str = "name", ident: str = "id") -> Graph[Incomplete]: ... +def cytoscape_graph(data: Mapping[str, Incomplete], name: str = "name", ident: str = "id") -> Graph[Incomplete]: ... diff --git a/stubs/networkx/networkx/readwrite/json_graph/node_link.pyi b/stubs/networkx/networkx/readwrite/json_graph/node_link.pyi index 15c7da4e2da3..db75b20b2de0 100644 --- a/stubs/networkx/networkx/readwrite/json_graph/node_link.pyi +++ b/stubs/networkx/networkx/readwrite/json_graph/node_link.pyi @@ -1,4 +1,5 @@ from _typeshed import Incomplete +from collections.abc import Mapping from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable @@ -17,10 +18,9 @@ def node_link_data( ) -> dict[Incomplete, Incomplete]: ... @_dispatchable def node_link_graph( - data: dict[Incomplete, Incomplete], + data: Mapping[str, Incomplete], directed: bool = False, multigraph: bool = True, - attrs=None, *, source: str = "source", target: str = "target", diff --git a/stubs/networkx/networkx/readwrite/json_graph/tree.pyi b/stubs/networkx/networkx/readwrite/json_graph/tree.pyi index 052e8b5fb2b5..e14b076a3cf8 100644 --- a/stubs/networkx/networkx/readwrite/json_graph/tree.pyi +++ b/stubs/networkx/networkx/readwrite/json_graph/tree.pyi @@ -1,4 +1,5 @@ from _typeshed import Incomplete +from collections.abc import Mapping from networkx.classes.digraph import DiGraph from networkx.classes.graph import _Node @@ -8,4 +9,4 @@ __all__ = ["tree_data", "tree_graph"] def tree_data(G: DiGraph[_Node], root, ident: str = "id", children: str = "children") -> dict[Incomplete, Incomplete]: ... @_dispatchable -def tree_graph(data: dict[Incomplete, Incomplete], ident: str = "id", children: str = "children") -> DiGraph[Incomplete]: ... +def tree_graph(data: Mapping[str, Incomplete], ident: str = "id", children: str = "children") -> DiGraph[Incomplete]: ... diff --git a/stubs/networkx/networkx/readwrite/multiline_adjlist.pyi b/stubs/networkx/networkx/readwrite/multiline_adjlist.pyi index ae269ad60fb1..7c755ddd7eaa 100644 --- a/stubs/networkx/networkx/readwrite/multiline_adjlist.pyi +++ b/stubs/networkx/networkx/readwrite/multiline_adjlist.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete, StrPath, SupportsRead, SupportsWrite -from collections.abc import Generator, Iterable +from collections.abc import Callable, Generator, Iterator from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable @@ -12,12 +12,12 @@ def write_multiline_adjlist( ) -> None: ... @_dispatchable def parse_multiline_adjlist( - lines: Iterable[str], + lines: Iterator[str], comments: str = "#", delimiter: str | None = None, create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None, - nodetype: type[Incomplete] | None = None, - edgetype: type[Incomplete] | None = None, + nodetype: Callable[[str], Incomplete] | None = None, + edgetype: Callable[[str], Incomplete] | None = None, ) -> Graph[Incomplete]: ... @_dispatchable def read_multiline_adjlist( @@ -25,7 +25,7 @@ def read_multiline_adjlist( comments: str = "#", delimiter: str | None = None, create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None, - nodetype: type[Incomplete] | None = None, - edgetype: type[Incomplete] | None = None, + nodetype: Callable[[str], Incomplete] | None = None, + edgetype: Callable[[str], Incomplete] | None = None, encoding: str = "utf-8", ) -> Graph[Incomplete]: ... diff --git a/stubs/networkx/networkx/utils/decorators.pyi b/stubs/networkx/networkx/utils/decorators.pyi index 66d2cd8121d5..2c78d5c31bc0 100644 --- a/stubs/networkx/networkx/utils/decorators.pyi +++ b/stubs/networkx/networkx/utils/decorators.pyi @@ -1,18 +1,20 @@ from _typeshed import Incomplete -from collections.abc import Callable, Sequence +from collections.abc import Callable, Iterable from typing import NamedTuple __all__ = ["not_implemented_for", "open_file", "nodes_or_number", "np_random_state", "py_random_state", "argmap"] -def not_implemented_for(*graph_types) -> Callable[..., Incomplete]: ... -def open_file(path_arg: str | int, mode: str = "r") -> Callable[..., Incomplete]: ... -def nodes_or_number(which_args: str | int | Sequence[str | int]) -> Callable[..., Incomplete]: ... -def np_random_state(random_state_argument: str | int) -> Callable[..., Incomplete]: ... -def py_random_state(random_state_argument: str | int) -> Callable[..., Incomplete]: ... +def not_implemented_for(*graph_types: str) -> argmap: ... +def open_file(path_arg: str | int, mode: str = "r") -> argmap: ... +def nodes_or_number( + which_args: int | Iterable[str | int], # A bare str is iterated per character, not used as a single argument name +) -> argmap: ... +def np_random_state(random_state_argument: str | int) -> argmap: ... +def py_random_state(random_state_argument: str | int) -> argmap: ... class argmap: - def __init__(self, func, *args, try_finally: bool = False) -> None: ... - def __call__(self, f) -> Callable[..., Incomplete]: ... + def __init__(self, func: Callable[..., Incomplete], *args, try_finally: bool = False) -> None: ... + def __call__(self, f: Callable[..., Incomplete]) -> Callable[..., Incomplete]: ... def compile(self, f: Callable[..., Incomplete]) -> Callable[..., Incomplete]: ... def assemble(self, f: Callable[..., Incomplete]): ... @classmethod