networkx: Add type annotation to all G params (#14796)

This commit is contained in:
Avasam
2025-09-30 06:22:18 -04:00
committed by GitHub
parent 284acd45d3
commit 810433f176
47 changed files with 183 additions and 118 deletions
@@ -6,9 +6,11 @@ from networkx.utils.backends import _dispatchable
__all__ = ["generate_edgelist", "write_edgelist", "parse_edgelist", "read_edgelist"]
@_dispatchable
def write_edgelist(G, path, comments: str = "#", delimiter: str = " ", data: bool = True, encoding: str = "utf-8") -> None: ...
def write_edgelist(
G: Graph[_Node], path, comments: str = "#", delimiter: str = " ", data: bool = True, encoding: str = "utf-8"
) -> None: ...
@_dispatchable
def generate_edgelist(G, delimiter: str = " ", data: bool = True) -> Generator[str]: ...
def generate_edgelist(G: Graph[_Node], delimiter: str = " ", data: bool = True) -> Generator[str]: ...
@_dispatchable
def parse_edgelist(
lines,
@@ -1,10 +1,11 @@
from _typeshed import Incomplete
from collections.abc import Generator
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
@_dispatchable
def flow_matrix_row(G, weight=None, dtype=..., solver: str = "lu") -> Generator[Incomplete, None, None]: ...
def flow_matrix_row(G: Graph[_Node], weight=None, dtype=..., solver: str = "lu") -> Generator[Incomplete, None, None]: ...
class InverseLaplacian:
dtype: Incomplete
@@ -26,4 +26,4 @@ def chordal_graph_cliques(G: Graph[_Node]) -> Generator[frozenset[_Node], None,
@_dispatchable
def chordal_graph_treewidth(G: Graph[_Node]) -> int: ...
@_dispatchable
def complete_to_chordal_graph(G) -> tuple[Incomplete, dict[Incomplete, int]]: ...
def complete_to_chordal_graph(G: Graph[_Node]) -> tuple[Incomplete, dict[Incomplete, int]]: ...
@@ -34,9 +34,9 @@ def node_clique_number(
) -> dict[_Node, int]: ...
@overload
def node_clique_number(G: Graph[_Node], nodes=None, cliques: Iterable[Incomplete] | None = None, separate_nodes=False) -> int: ...
def number_of_cliques(G, nodes=None, cliques=None) -> int | dict[Incomplete, Incomplete]: ...
def number_of_cliques(G: Graph[_Node], nodes=None, cliques=None) -> int | dict[Incomplete, Incomplete]: ...
@_dispatchable
def max_weight_clique(G, weight="weight") -> tuple[list[Incomplete], int]: ...
def max_weight_clique(G: Graph[_Node], weight="weight") -> tuple[list[Incomplete], int]: ...
class MaxWeightClique:
G: Graph[Incomplete]
@@ -1,4 +1,4 @@
from _typeshed import Incomplete
from _typeshed import Incomplete, Unused
from collections.abc import Callable, Generator
from typing import Final
@@ -18,21 +18,23 @@ __all__ = [
]
@_dispatchable
def strategy_largest_first(G, colors): ...
def strategy_largest_first(G: Graph[_Node], colors: Unused): ...
@_dispatchable
def strategy_random_sequential(G, colors, seed=None): ...
def strategy_random_sequential(G: Graph[_Node], colors: Unused, seed=None): ...
@_dispatchable
def strategy_smallest_last(G, colors): ...
def strategy_smallest_last(G: Graph[_Node], colors: Unused): ...
@_dispatchable
def strategy_independent_set(G, colors) -> Generator[Incomplete, Incomplete, None]: ...
def strategy_independent_set(G: Graph[_Node], colors: Unused) -> Generator[Incomplete, Incomplete, None]: ...
@_dispatchable
def strategy_connected_sequential_bfs(G, colors): ...
def strategy_connected_sequential_bfs(G: Graph[_Node], colors): ...
@_dispatchable
def strategy_connected_sequential_dfs(G, colors): ...
def strategy_connected_sequential_dfs(G: Graph[_Node], colors): ...
@_dispatchable
def strategy_connected_sequential(G, colors, traversal: str = "bfs") -> Generator[Incomplete, None, None]: ...
def strategy_connected_sequential(
G: Graph[_Node], colors: Unused, traversal: str = "bfs"
) -> Generator[Incomplete, None, None]: ...
@_dispatchable
def strategy_saturation_largest_first(G, colors) -> Generator[Incomplete, None, Incomplete]: ...
def strategy_saturation_largest_first(G: Graph[_Node], colors) -> Generator[Incomplete, None, Incomplete]: ...
STRATEGIES: Final[dict[str, Callable[..., Incomplete]]]
@@ -9,7 +9,7 @@ from numpy.random import RandomState
__all__ = ["label_propagation_communities", "asyn_lpa_communities", "fast_label_propagation_communities"]
@_dispatchable
def fast_label_propagation_communities(G, *, weight=None, seed=None) -> Generator[Incomplete]: ...
def fast_label_propagation_communities(G: Graph[_Node], *, weight=None, seed=None) -> Generator[Incomplete]: ...
@_dispatchable
def asyn_lpa_communities(
G: Graph[_Node], weight: str | None = None, seed: int | RandomState | None = None
@@ -6,7 +6,7 @@ from networkx.utils.decorators import argmap
__all__ = ["modularity", "partition_quality"]
class NotAPartition(NetworkXError):
def __init__(self, G, collection) -> None: ...
def __init__(self, G: Graph[_Node], collection) -> None: ...
require_partition: argmap
@@ -18,7 +18,7 @@ class EdgeComponentAuxGraph:
H: Incomplete
@classmethod
def construct(cls, G): ...
def construct(cls, G: Graph[_Node]): ...
def k_edge_components(self, k: int) -> Generator[Incomplete, Incomplete, None]: ...
def k_edge_subgraphs(self, k: int) -> Generator[Incomplete, Incomplete, None]: ...
@@ -1,8 +1,9 @@
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = ["build_auxiliary_node_connectivity", "build_auxiliary_edge_connectivity"]
@_dispatchable
def build_auxiliary_node_connectivity(G): ...
def build_auxiliary_node_connectivity(G: Graph[_Node]): ...
@_dispatchable
def build_auxiliary_edge_connectivity(G): ...
def build_auxiliary_edge_connectivity(G: Graph[_Node]): ...
@@ -9,7 +9,7 @@ __all__ = ["is_d_separator", "is_minimal_d_separator", "find_minimal_d_separator
@_dispatchable
def is_d_separator(G: DiGraph[_Node], x: _Node | set[_Node], y: _Node | set[_Node], z: _Node | set[_Node]) -> bool: ...
@_dispatchable
def find_minimal_d_separator(G, x, y, *, included=None, restricted=None) -> set[Incomplete] | None: ...
def find_minimal_d_separator(G: DiGraph[_Node], x, y, *, included=None, restricted=None) -> set[Incomplete] | None: ...
@_dispatchable
def is_minimal_d_separator(
G: DiGraph[_Node],
+2 -2
View File
@@ -60,6 +60,6 @@ def dag_longest_path(
@_dispatchable
def dag_longest_path_length(G: DiGraph[_Node], weight: str | None = "weight", default_weight: int | None = 1) -> int: ...
@_dispatchable
def dag_to_branching(G: Graph[_Node]) -> DiGraph[_Node]: ...
def dag_to_branching(G: DiGraph[_Node]) -> DiGraph[_Node]: ...
@_dispatchable
def compute_v_structures(G) -> Generator[tuple[Incomplete, Incomplete, Incomplete]]: ...
def compute_v_structures(G: DiGraph[_Node]) -> Generator[tuple[Incomplete, Incomplete, Incomplete]]: ...
@@ -1,11 +1,11 @@
from networkx.classes.graph import _Node
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = ["efficiency", "local_efficiency", "global_efficiency"]
@_dispatchable
def efficiency(G, u: _Node, v: _Node) -> float: ...
def efficiency(G: Graph[_Node], u: _Node, v: _Node) -> float: ...
@_dispatchable
def global_efficiency(G) -> float: ...
def global_efficiency(G: Graph[_Node]) -> float: ...
@_dispatchable
def local_efficiency(G) -> float: ...
def local_efficiency(G: Graph[_Node]) -> float: ...
@@ -26,7 +26,9 @@ class _DataEssentialsAndFunctions:
prev_node_dft: Incomplete
last_descendent_dft: Incomplete
def __init__(self, G, multigraph, demand: str = "demand", capacity: str = "capacity", weight: str = "weight") -> None: ...
def __init__(
self, G: Graph[_Node], multigraph, demand: str = "demand", capacity: str = "capacity", weight: str = "weight"
) -> None: ...
def initialize_spanning_tree(self, n, faux_inf) -> None: ...
def find_apex(self, p, q): ...
def trace_path(self, p, w): ...
@@ -1,5 +1,9 @@
from _typeshed import Incomplete
from typing import NoReturn, overload
from typing_extensions import deprecated
from networkx.classes.graph import Graph, _Node
from networkx.classes.multigraph import MultiGraph
from networkx.utils.backends import _dispatchable
__all__ = ["CurrentEdge", "Level", "GlobalRelabelThreshold", "build_residual_network", "detect_unboundedness", "build_flow_dict"]
@@ -23,9 +27,12 @@ class GlobalRelabelThreshold:
def is_reached(self) -> bool: ...
def clear_work(self) -> None: ...
@_dispatchable
def build_residual_network(G, capacity): ...
@overload
@deprecated("MultiGraph and MultiDiGraph not supported (yet).")
def build_residual_network(G: MultiGraph[_Node], capacity, *, backend: str | None = None, **backend_kwargs) -> NoReturn: ...
@overload
def build_residual_network(G: Graph[_Node], capacity, *, backend: str | None = None, **backend_kwargs): ...
@_dispatchable
def detect_unboundedness(R, s, t) -> None: ...
@_dispatchable
def build_flow_dict(G, R): ...
def build_flow_dict(G: Graph[_Node], R): ...
@@ -1,6 +1,8 @@
from networkx.classes.digraph import DiGraph
from networkx.classes.graph import _Node
from networkx.utils.backends import _dispatchable
__all__ = ["flow_hierarchy"]
@_dispatchable
def flow_hierarchy(G, weight: str | None = None) -> float: ...
def flow_hierarchy(G: DiGraph[_Node], weight: str | None = None) -> float: ...
@@ -23,6 +23,6 @@ _Y_co = TypeVar("_Y_co", bound=Hashable, covariant=True)
@_dispatchable
def compose(G: Graph[_X_co], H: Graph[_Y_co]) -> DiGraph[_X_co | _Y_co]: ...
@_dispatchable
def full_join(G, H, rename=(None, None)): ...
def full_join(G: Graph[_Node], H, rename=(None, None)): ...
@_dispatchable
def union(G: Graph[_X_co], H: Graph[_Y_co], rename: Iterable[Incomplete] | None = ()) -> DiGraph[_X_co | _Y_co]: ...
@@ -34,4 +34,4 @@ def rooted_product(G: Graph[_X], H: Graph[_Y], root: _Y) -> Graph[tuple[_X, _Y]]
@_dispatchable
def corona_product(G: Graph[_X], H: Graph[_Y]) -> Graph[tuple[_X, _Y]]: ...
@_dispatchable
def modular_product(G, H) -> Graph[Incomplete]: ...
def modular_product(G: Graph[_Node], H) -> Graph[Incomplete]: ...
@@ -73,7 +73,7 @@ class LRPlanarity:
right_ref: Incomplete
embedding: Incomplete
def __init__(self, G) -> None: ...
def __init__(self, G: Graph[_Node]) -> None: ...
def lr_planarity(self) -> PlanarEmbedding[Incomplete] | None: ...
def lr_planarity_recursive(self): ...
def dfs_orientation(self, v): ...
@@ -39,7 +39,7 @@ def minimum_branching(
G: DiGraph[_Node], attr: str = "weight", default: float = 1, preserve_attrs: bool = False, partition: str | None = None
): ...
@_dispatchable
def minimal_branching(G, /, *, attr="weight", default=1, preserve_attrs=False, partition=None): ...
def minimal_branching(G: DiGraph[_Node], /, *, attr="weight", default=1, preserve_attrs=False, partition=None): ...
@_dispatchable
def maximum_spanning_arborescence(
G: DiGraph[_Node], attr: str = "weight", default: float = 1, preserve_attrs: bool = False, partition: str | None = None
@@ -63,7 +63,7 @@ class ArborescenceIterator:
partition_key: str
init_partition: Incomplete
def __init__(self, G, weight: str = "weight", minimum: bool = True, init_partition=None) -> None: ...
def __init__(self, G: DiGraph[_Node], weight: str = "weight", minimum: bool = True, init_partition=None) -> None: ...
partition_queue: Incomplete
def __iter__(self) -> Self: ...
@@ -1,9 +1,9 @@
from _typeshed import Incomplete
from networkx.classes.graph import Graph
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = ["junction_tree"]
@_dispatchable
def junction_tree(G) -> Graph[Incomplete]: ...
def junction_tree(G: Graph[_Node]) -> Graph[Incomplete]: ...
@@ -5,6 +5,7 @@ from enum import Enum
from typing import Final, Literal
from typing_extensions import Self
from networkx.classes.digraph import DiGraph
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
from numpy.random import RandomState
@@ -79,11 +80,11 @@ class SpanningTreeIterator:
ignore_nan: Incomplete
partition_key: str
def __init__(self, G, weight: str = "weight", minimum: bool = True, ignore_nan: bool = False) -> None: ...
def __init__(self, G: DiGraph[_Node], weight: str = "weight", minimum: bool = True, ignore_nan: bool = False) -> None: ...
partition_queue: Incomplete
def __iter__(self) -> Self: ...
def __next__(self): ...
@_dispatchable
def number_of_spanning_trees(G, *, root=None, weight=None) -> float | Literal[0]: ...
def number_of_spanning_trees(G: Graph[_Node], *, root=None, weight=None) -> float | Literal[0]: ...
@@ -6,6 +6,6 @@ __all__ = ["wiener_index", "schultz_index", "gutman_index"]
@_dispatchable
def wiener_index(G: Graph[_Node], weight: str | None = None) -> float: ...
@_dispatchable
def schultz_index(G, weight=None) -> float: ...
def schultz_index(G: Graph[_Node], weight=None) -> float: ...
@_dispatchable
def gutman_index(G, weight=None) -> float: ...
def gutman_index(G: Graph[_Node], weight=None) -> float: ...
+26 -19
View File
@@ -52,32 +52,32 @@ __all__ = [
_U = TypeVar("_U")
def nodes(G): ...
def edges(G, nbunch=None): ...
def degree(G, nbunch=None, weight=None): ...
def neighbors(G, n): ...
def number_of_nodes(G): ...
def number_of_edges(G): ...
def density(G): ...
def degree_histogram(G) -> list[int]: ...
def nodes(G: Graph[_Node]): ...
def edges(G: Graph[_Node], nbunch=None): ...
def degree(G: Graph[_Node], nbunch=None, weight=None): ...
def neighbors(G: Graph[_Node], n): ...
def number_of_nodes(G: Graph[_Node]): ...
def number_of_edges(G: Graph[_Node]): ...
def density(G: Graph[_Node]): ...
def degree_histogram(G: Graph[_Node]) -> list[int]: ...
@overload
def is_directed(G: PlanarEmbedding[Hashable]) -> Literal[False]: ... # type: ignore[misc] # Incompatible return types
@overload
def is_directed(G: DiGraph[Hashable]) -> Literal[True]: ... # type: ignore[misc] # Incompatible return types
@overload
def is_directed(G: Graph[Hashable]) -> Literal[False]: ...
def freeze(G): ...
def freeze(G: Graph[_Node]): ...
def is_frozen(G: Graph[Incomplete]) -> bool: ...
def add_star(G_to_add_to, nodes_for_star, **attr) -> None: ...
def add_path(G_to_add_to, nodes_for_path, **attr) -> None: ...
def add_cycle(G_to_add_to, nodes_for_cycle, **attr) -> None: ...
def subgraph(G, nbunch): ...
def subgraph(G: Graph[_Node], nbunch): ...
def induced_subgraph(G: Graph[_Node], nbunch: _NBunch[_Node]) -> Graph[_Node]: ...
def edge_subgraph(G, edges): ...
def restricted_view(G, nodes, edges): ...
def edge_subgraph(G: Graph[_Node], edges): ...
def restricted_view(G: Graph[_Node], nodes, edges): ...
def to_directed(graph): ...
def to_undirected(graph): ...
def create_empty_copy(G, with_data: bool = True): ...
def create_empty_copy(G: Graph[_Node], with_data: bool = True): ...
# incomplete: Can "Any scalar value" be enforced?
@overload
@@ -101,26 +101,33 @@ def set_node_attributes(
@_dispatchable
def get_node_attributes(G: Graph[_Node], name: str, default=None) -> dict[_Node, Incomplete]: ...
@_dispatchable
def remove_node_attributes(G, *attr_names, nbunch=None) -> None: ...
def remove_node_attributes(G: Graph[_Node], *attr_names, nbunch=None) -> None: ...
@overload
def set_edge_attributes(
G: Graph[_Node],
values: SupportsItems[tuple[_Node, _Node], Incomplete],
name: str,
*,
backend=None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload
backend: str | None = None, # @_dispatchable adds these arguments, but we can't use this decorator with @overload
**backend_kwargs,
) -> None: ...
@overload
def set_edge_attributes(
G: MultiGraph[_Node], values: dict[tuple[_Node, _Node, Incomplete], Incomplete], name: str, *, backend=None, **backend_kwargs
G: MultiGraph[_Node],
values: dict[tuple[_Node, _Node, Incomplete], Incomplete],
name: str,
*,
backend: str | None = None,
**backend_kwargs,
) -> None: ...
@overload
def set_edge_attributes(G: Graph[Hashable], values, name: None = None, *, backend=None, **backend_kwargs) -> None: ...
def set_edge_attributes(
G: Graph[Hashable], values, name: None = None, *, backend: str | None = None, **backend_kwargs
) -> None: ...
@_dispatchable
def get_edge_attributes(G: Graph[_Node], name: str, default=None) -> dict[tuple[_Node, _Node], Incomplete]: ...
@_dispatchable
def remove_edge_attributes(G, *attr_names, ebunch=None) -> None: ...
def remove_edge_attributes(G: Graph[_Node], *attr_names, ebunch=None) -> None: ...
def all_neighbors(graph: Graph[_Node], node: _Node) -> Iterator[_Node]: ...
def non_neighbors(graph: Graph[_Node], node: _Node) -> Generator[_Node, None, None]: ...
def non_edges(graph: Graph[_Node]) -> Generator[tuple[_Node, _Node], None, None]: ...
@@ -163,4 +170,4 @@ def selfloop_edges(
@_dispatchable
def number_of_selfloops(G: Graph[Hashable]) -> int: ...
def is_path(G: Graph[_Node], path: Iterable[Incomplete]) -> bool: ...
def path_weight(G, path, weight) -> int: ...
def path_weight(G: Graph[_Node], path, weight) -> int: ...
+1 -1
View File
@@ -80,7 +80,7 @@ def from_pandas_edgelist(
edge_key: str | None = None,
) -> Graph[Incomplete]: ...
@_dispatchable
def to_scipy_sparse_array(G, nodelist=None, dtype=None, weight="weight", format="csr"): ...
def to_scipy_sparse_array(G: Graph[_Node], nodelist=None, dtype=None, weight="weight", format="csr"): ...
@_dispatchable
def from_scipy_sparse_array(A, parallel_edges=False, create_using=None, edge_attribute="weight"): ...
@_dispatchable
+2 -1
View File
@@ -1,6 +1,7 @@
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = ["ego_graph"]
@_dispatchable
def ego_graph(G, n, radius: float = 1, center: bool = True, undirected: bool = False, distance=None): ...
def ego_graph(G: Graph[_Node], n, radius: float = 1, center: bool = True, undirected: bool = False, distance=None): ...
@@ -1,6 +1,6 @@
from _typeshed import Incomplete
from networkx.classes.graph import Graph
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = [
@@ -15,7 +15,7 @@ __all__ = [
]
@_dispatchable
def geometric_edges(G, radius, p: float = 2): ...
def geometric_edges(G: Graph[_Node], radius, p: float = 2): ...
@_dispatchable
def random_geometric_graph(n, radius, dim: int = 2, pos=None, p: float = 2, seed=None): ...
@_dispatchable
+3 -2
View File
@@ -1,8 +1,9 @@
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = ["line_graph", "inverse_line_graph"]
@_dispatchable
def line_graph(G, create_using=None): ...
def line_graph(G: Graph[_Node], create_using=None): ...
@_dispatchable
def inverse_line_graph(G): ...
def inverse_line_graph(G: Graph[_Node]): ...
@@ -1,8 +1,9 @@
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = ["mycielskian", "mycielski_graph"]
@_dispatchable
def mycielskian(G, iterations: int = 1): ...
def mycielskian(G: Graph[_Node], iterations: int = 1): ...
@_dispatchable
def mycielski_graph(n): ...
@@ -1,10 +1,9 @@
from _typeshed import Incomplete
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
from ..classes.graph import Graph
__all__ = ["spectral_graph_forge"]
@_dispatchable
def spectral_graph_forge(G, alpha, transformation: str = "identity", seed=None) -> Graph[Incomplete]: ...
def spectral_graph_forge(G: Graph[_Node], alpha, transformation: str = "identity", seed=None) -> Graph[Incomplete]: ...
@@ -1,6 +1,8 @@
from networkx.classes.digraph import DiGraph
from networkx.classes.graph import _Node
from networkx.utils.backends import _dispatchable
__all__ = ["stochastic_graph"]
@_dispatchable
def stochastic_graph(G, copy: bool = True, weight: str = "weight"): ...
def stochastic_graph(G: DiGraph[_Node], copy: bool = True, weight: str = "weight"): ...
@@ -1,11 +1,12 @@
from collections.abc import Generator
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = ["generate_adjlist", "write_adjlist", "parse_adjlist", "read_adjlist"]
def generate_adjlist(G, delimiter: str = " ") -> Generator[str, None, None]: ...
def write_adjlist(G, path, comments: str = "#", delimiter: str = " ", encoding: str = "utf-8") -> None: ...
def generate_adjlist(G: Graph[_Node], delimiter: str = " ") -> Generator[str, None, None]: ...
def write_adjlist(G: Graph[_Node], path, comments: str = "#", delimiter: str = " ", encoding: str = "utf-8") -> None: ...
@_dispatchable
def parse_adjlist(lines, comments: str = "#", delimiter=None, create_using=None, nodetype=None): ...
@_dispatchable
@@ -1,6 +1,7 @@
from _typeshed import Incomplete
from collections.abc import Generator
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = [
@@ -12,8 +13,10 @@ __all__ = [
"write_weighted_edgelist",
]
def generate_edgelist(G, delimiter: str = " ", data: bool = True) -> Generator[Incomplete, None, None]: ...
def write_edgelist(G, path, comments: str = "#", delimiter: str = " ", data: bool = True, encoding: str = "utf-8") -> None: ...
def generate_edgelist(G: Graph[_Node], delimiter: str = " ", data: bool = True) -> Generator[Incomplete, None, None]: ...
def write_edgelist(
G: Graph[_Node], path, comments: str = "#", delimiter: str = " ", data: bool = True, encoding: str = "utf-8"
) -> None: ...
@_dispatchable
def parse_edgelist(lines, comments: str = "#", delimiter=None, create_using=None, nodetype=None, data: bool = True): ...
@_dispatchable
@@ -27,7 +30,9 @@ def read_edgelist(
edgetype=None,
encoding: str = "utf-8",
): ...
def write_weighted_edgelist(G, path, comments: str = "#", delimiter: str = " ", encoding: str = "utf-8") -> None: ...
def write_weighted_edgelist(
G: Graph[_Node], path, comments: str = "#", delimiter: str = " ", encoding: str = "utf-8"
) -> None: ...
@_dispatchable
def read_weighted_edgelist(
path, comments: str = "#", delimiter=None, create_using=None, nodetype=None, encoding: str = "utf-8"
+9 -8
View File
@@ -2,13 +2,14 @@ from _typeshed import Incomplete
from collections.abc import Generator
from typing import Final, Literal
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = ["write_gexf", "read_gexf", "relabel_gexf_graph", "generate_gexf"]
def write_gexf(G, path, encoding: str = "utf-8", prettyprint: bool = True, version: str = "1.2draft") -> None: ...
def write_gexf(G: Graph[_Node], path, encoding: str = "utf-8", prettyprint: bool = True, version: str = "1.2draft") -> None: ...
def generate_gexf(
G, encoding: str = "utf-8", prettyprint: bool = True, version: str = "1.2draft"
G: Graph[_Node], encoding: str = "utf-8", prettyprint: bool = True, version: str = "1.2draft"
) -> Generator[Incomplete, Incomplete, None]: ...
@_dispatchable
def read_gexf(path, node_type=None, relabel: bool = False, version: str = "1.2draft"): ...
@@ -37,9 +38,9 @@ class GEXFWriter(GEXF):
attr: Incomplete
def __init__(self, graph=None, encoding: str = "utf-8", prettyprint: bool = True, version: str = "1.2draft") -> None: ...
graph_element: Incomplete
def add_graph(self, G) -> None: ...
def add_nodes(self, G, graph_element) -> None: ...
def add_edges(self, G, graph_element) -> None: ...
def add_graph(self, G: Graph[_Node]) -> None: ...
def add_nodes(self, G: Graph[_Node], graph_element) -> None: ...
def add_edges(self, G: Graph[_Node], graph_element) -> None: ...
def add_attributes(self, node_or_edge, xml_obj, data, default): ...
def get_attr_id(self, title, attr_type, edge_or_node, default, mode): ...
def add_viz(self, element, node_data): ...
@@ -58,14 +59,14 @@ class GEXFReader(GEXF):
def __call__(self, stream): ...
timeformat: Incomplete
def make_graph(self, graph_xml): ...
def add_node(self, G, node_xml, node_attr, node_pid=None) -> None: ...
def add_node(self, G: Graph[_Node], node_xml, node_attr, node_pid=None) -> None: ...
def add_start_end(self, data, xml): ...
def add_viz(self, data, node_xml): ...
def add_parents(self, data, node_xml): ...
def add_slices(self, data, node_or_edge_xml): ...
def add_spells(self, data, node_or_edge_xml): ...
def add_edge(self, G, edge_element, edge_attr) -> None: ...
def add_edge(self, G: Graph[_Node], edge_element, edge_attr) -> None: ...
def decode_attr_elements(self, gexf_keys, obj_xml): ...
def find_gexf_attributes(self, attributes_element): ...
def relabel_gexf_graph(G): ...
def relabel_gexf_graph(G: Graph[_Node]): ...
+3 -2
View File
@@ -3,6 +3,7 @@ from collections.abc import Generator
from enum import Enum
from typing import Final, Generic, NamedTuple, TypeVar
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
_T = TypeVar("_T")
@@ -36,5 +37,5 @@ LIST_START_VALUE: Final = "_networkx_list_start"
def parse_gml_lines(lines, label, destringizer): ...
def literal_stringizer(value) -> str: ...
def generate_gml(G, stringizer=None) -> Generator[Incomplete, Incomplete, None]: ...
def write_gml(G, path, stringizer=None) -> None: ...
def generate_gml(G: Graph[_Node], stringizer=None) -> Generator[Incomplete, Incomplete, None]: ...
def write_gml(G: Graph[_Node], path, stringizer=None) -> None: ...
+2 -2
View File
@@ -8,10 +8,10 @@ __all__ = ["from_graph6_bytes", "read_graph6", "to_graph6_bytes", "write_graph6"
@_dispatchable
def from_graph6_bytes(bytes_in) -> Graph[Incomplete]: ...
def to_graph6_bytes(G, nodes=None, header: bool = True): ...
def to_graph6_bytes(G: Graph[_Node], nodes=None, header: bool = True): ...
@_dispatchable
def read_graph6(path): ...
def write_graph6(G, path, nodes=None, header: bool = True): ...
def write_graph6(G: Graph[_Node], path, nodes=None, header: bool = True): ...
def write_graph6_file(G: Graph[_Node], f, nodes: Iterable[Incomplete] | None = None, header: bool = True): ...
def data_to_n(data): ...
def n_to_data(n): ...
+10 -9
View File
@@ -2,6 +2,7 @@ from _typeshed import Incomplete
from collections.abc import Generator
from typing import Final, Literal
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = [
@@ -16,7 +17,7 @@ __all__ = [
]
def write_graphml_xml(
G,
G: Graph[_Node],
path,
encoding: str = "utf-8",
prettyprint: bool = True,
@@ -25,7 +26,7 @@ def write_graphml_xml(
edge_id_from_attribute=None,
) -> None: ...
def write_graphml_lxml(
G,
G: Graph[_Node],
path,
encoding: str = "utf-8",
prettyprint: bool = True,
@@ -34,7 +35,7 @@ def write_graphml_lxml(
edge_id_from_attribute=None,
): ...
def generate_graphml(
G, encoding: str = "utf-8", prettyprint: bool = True, named_key_ids: bool = False, edge_id_from_attribute=None
G: Graph[_Node], encoding: str = "utf-8", prettyprint: bool = True, named_key_ids: bool = False, edge_id_from_attribute=None
) -> Generator[Incomplete, Incomplete, None]: ...
@_dispatchable
def read_graphml(path, node_type=..., edge_key_type=..., force_multigraph: bool = False): ...
@@ -76,9 +77,9 @@ class GraphMLWriter(GraphML):
def get_key(self, name, attr_type, scope, default): ...
def add_data(self, name, element_type, value, scope: str = "all", default=None): ...
def add_attributes(self, scope, xml_obj, data, default) -> None: ...
def add_nodes(self, G, graph_element) -> None: ...
def add_edges(self, G, graph_element) -> None: ...
def add_graph_element(self, G) -> None: ...
def add_nodes(self, G: Graph[_Node], graph_element) -> None: ...
def add_edges(self, G: Graph[_Node], graph_element) -> None: ...
def add_graph_element(self, G: Graph[_Node]) -> None: ...
def add_graphs(self, graph_list) -> None: ...
def dump(self, stream) -> None: ...
def indent(self, elem, level: int = 0) -> None: ...
@@ -107,7 +108,7 @@ class GraphMLWriterLxml(GraphMLWriter):
named_key_ids: bool = False,
edge_id_from_attribute=None,
) -> None: ...
def add_graph_element(self, G) -> None: ...
def add_graph_element(self, G: Graph[_Node]) -> None: ...
def add_attributes(self, scope, xml_obj, data, default) -> None: ...
def dump(self, stream=None) -> None: ...
@@ -122,7 +123,7 @@ class GraphMLReader(GraphML):
xml: Incomplete
def __call__(self, path=None, string=None) -> Generator[Incomplete, None, None]: ...
def make_graph(self, graph_xml, graphml_keys, defaults, G=None): ...
def add_node(self, G, node_xml, graphml_keys, defaults) -> None: ...
def add_edge(self, G, edge_element, graphml_keys) -> None: ...
def add_node(self, G: Graph[_Node], node_xml, graphml_keys, defaults) -> None: ...
def add_edge(self, G: Graph[_Node], edge_element, graphml_keys) -> None: ...
def decode_data_elements(self, graphml_keys, obj_xml): ...
def find_graphml_keys(self, graph_element): ...
@@ -1,10 +1,11 @@
from typing import Any
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = ["adjacency_data", "adjacency_graph"]
# Any: Complex type union
def adjacency_data(G, attrs={"id": "id", "key": "key"}) -> dict[str, Any]: ...
def adjacency_data(G: Graph[_Node], attrs={"id": "id", "key": "key"}) -> dict[str, Any]: ...
@_dispatchable
def adjacency_graph(data, directed: bool = False, multigraph: bool = True, attrs={"id": "id", "key": "key"}): ...
@@ -1,10 +1,11 @@
from typing import Any
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = ["cytoscape_data", "cytoscape_graph"]
# Any: Complex type union
def cytoscape_data(G, name: str = "name", ident: str = "id") -> dict[str, Any]: ...
def cytoscape_data(G: Graph[_Node], name: str = "name", ident: str = "id") -> dict[str, Any]: ...
@_dispatchable
def cytoscape_graph(data, name: str = "name", ident: str = "id"): ...
@@ -1,9 +1,19 @@
from typing import overload
from typing_extensions import deprecated
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = ["node_link_data", "node_link_graph"]
@overload
@deprecated(
"""\
The `link` argument is deprecated and will be removed in version `3.6`.
Use the `edges` keyword instead."""
)
def node_link_data(
G,
G: Graph[_Node],
*,
source: str = "source",
target: str = "target",
@@ -13,6 +23,17 @@ def node_link_data(
nodes: str = "nodes",
link: str | None = None,
): ...
@overload
def node_link_data(
G: Graph[_Node],
*,
source: str = "source",
target: str = "target",
name: str = "id",
key: str = "key",
edges: str | None = None,
nodes: str = "nodes",
): ...
@_dispatchable
def node_link_graph(
data,
@@ -1,7 +1,9 @@
from networkx.classes.digraph import DiGraph
from networkx.classes.graph import _Node
from networkx.utils.backends import _dispatchable
__all__ = ["tree_data", "tree_graph"]
def tree_data(G, root, ident: str = "id", children: str = "children"): ...
def tree_data(G: DiGraph[_Node], root, ident: str = "id", children: str = "children"): ...
@_dispatchable
def tree_graph(data, ident: str = "id", children: str = "children"): ...
@@ -1,11 +1,12 @@
from collections.abc import Generator
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = ["generate_multiline_adjlist", "write_multiline_adjlist", "parse_multiline_adjlist", "read_multiline_adjlist"]
def generate_multiline_adjlist(G, delimiter: str = " ") -> Generator[str, None, None]: ...
def write_multiline_adjlist(G, path, delimiter=" ", comments="#", encoding="utf-8") -> None: ...
def generate_multiline_adjlist(G: Graph[_Node], delimiter: str = " ") -> Generator[str, None, None]: ...
def write_multiline_adjlist(G: Graph[_Node], path, delimiter=" ", comments="#", encoding="utf-8") -> None: ...
@_dispatchable
def parse_multiline_adjlist(lines, comments: str = "#", delimiter=None, create_using=None, nodetype=None, edgetype=None): ...
@_dispatchable
+3 -3
View File
@@ -1,10 +1,10 @@
from _typeshed import Incomplete
from networkx.classes.graph import Graph, _Node
from networkx.classes.multidigraph import MultiDiGraph
from networkx.utils.backends import _dispatchable
from ..classes.multidigraph import MultiDiGraph
def write_p2g(G, path, encoding: str = "utf-8") -> None: ...
def write_p2g(G: Graph[_Node], path, encoding: str = "utf-8") -> None: ...
@_dispatchable
def read_p2g(path, encoding: str = "utf-8") -> MultiDiGraph[Incomplete]: ...
@_dispatchable
+3 -2
View File
@@ -1,12 +1,13 @@
from _typeshed import Incomplete
from collections.abc import Generator
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
__all__ = ["read_pajek", "parse_pajek", "generate_pajek", "write_pajek"]
def generate_pajek(G) -> Generator[Incomplete, None, None]: ...
def write_pajek(G, path, encoding: str = "UTF-8") -> None: ...
def generate_pajek(G: Graph[_Node]) -> Generator[Incomplete, None, None]: ...
def write_pajek(G: Graph[_Node], path, encoding: str = "UTF-8") -> None: ...
@_dispatchable
def read_pajek(path, encoding: str = "UTF-8"): ...
@_dispatchable
@@ -1,14 +1,13 @@
from _typeshed import Incomplete
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
from ..classes.graph import Graph
__all__ = ["from_sparse6_bytes", "read_sparse6", "to_sparse6_bytes", "write_sparse6"]
@_dispatchable
def from_sparse6_bytes(string) -> Graph[Incomplete]: ...
def to_sparse6_bytes(G, nodes=None, header: bool = True): ...
def to_sparse6_bytes(G: Graph[_Node], nodes=None, header: bool = True): ...
@_dispatchable
def read_sparse6(path): ...
def write_sparse6(G, path, nodes=None, header: bool = True) -> None: ...
def write_sparse6(G: Graph[_Node], path, nodes=None, header: bool = True) -> None: ...
+1 -1
View File
@@ -52,7 +52,7 @@ class _dispatchable(Generic[_P, _R]):
def __signature__(self): ...
# Type system limitations doesn't allow us to define this as it truly should.
# But specifying backend with backend_kwargs isn't a common usecase anyway
# and specifying backend as explicitely None is possible but not intended.
# and specifying backend as explicitly None is possible but not intended.
# If this ever changes, update stubs/networkx/@tests/test_cases/check_dispatch_decorator.py
@overload
def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R: ...
+2 -1
View File
@@ -4,6 +4,7 @@ from types import ModuleType
from typing_extensions import Self, TypeAlias
import numpy
from networkx.classes.graph import Graph, _Node
__all__ = [
"flatten",
@@ -60,4 +61,4 @@ def create_py_random_state(random_state: _RandomState = None): ...
def nodes_equal(nodes1, nodes2) -> bool: ...
def edges_equal(edges1, edges2) -> bool: ...
def graphs_equal(graph1, graph2) -> bool: ...
def _clear_cache(G) -> None: ...
def _clear_cache(G: Graph[_Node]) -> None: ...
+2 -2
View File
@@ -5,7 +5,7 @@ from networkx.classes.graph import Graph, _Node
__all__ = ["cuthill_mckee_ordering", "reverse_cuthill_mckee_ordering"]
def cuthill_mckee_ordering(G, heuristic=None) -> Generator[Incomplete, Incomplete, None]: ...
def reverse_cuthill_mckee_ordering(G, heuristic=None): ...
def cuthill_mckee_ordering(G: Graph[_Node], heuristic=None) -> Generator[Incomplete, Incomplete, None]: ...
def reverse_cuthill_mckee_ordering(G: Graph[_Node], heuristic=None): ...
def connected_cuthill_mckee_ordering(G: Graph[_Node], heuristic=None): ...
def pseudo_peripheral_node(G: Graph[_Node]): ...