Skip to content
Draft
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
eb2b783
Merged networkx stubs from python-type-stubs
Avasam May 13, 2025
67402d1
Replace `: Incomplete | None = None` with `=None`
Avasam May 13, 2025
2037be3
Fix failing tests
Avasam May 13, 2025
16f2a66
Support `requires_python` in `runtests.py`
Avasam May 13, 2025
1dad75f
Support `requires_python` in `runtests.py`
Avasam May 13, 2025
1f6be6e
Merge branch 'main' of https://github.com/python/typeshed into networ…
Avasam May 13, 2025
d487295
Merge branch 'main' of https://github.com/python/typeshed into networ…
Avasam May 14, 2025
72cf2c9
Discard changes to stubs/networkx/networkx/drawing/nx_agraph.pyi
Avasam May 14, 2025
e17709f
Update stubs/networkx/networkx/classes/multidigraph.pyi
Avasam May 14, 2025
47f5f7c
Update stubs/networkx/networkx/classes/digraph.pyi
Avasam May 14, 2025
73dbdbf
Remove accidental extra symbols
Avasam May 16, 2025
8aa5a56
Merge branch 'main' of https://github.com/python/typeshed into networ…
Avasam May 16, 2025
a092752
Replace `Graph[Incomplete]` with `Graph[_Node]`
Avasam May 22, 2025
8ab7313
Merge branch 'main' of https://github.com/python/typeshed into networ…
Avasam May 22, 2025
071e34d
Merge branch 'main' of https://github.com/python/typeshed into networ…
Avasam May 26, 2025
f52e0ce
Merge branch 'main' of https://github.com/python/typeshed into networ…
Avasam Jul 25, 2025
6409a80
Pass tests
Avasam Jul 25, 2025
39f5442
Merge branch 'main' into networkx-merge-from-python-type-stubs
Avasam Aug 5, 2025
33f6249
Discard changes to stubs/networkx/networkx/classes/digraph.pyi
Avasam Aug 20, 2025
cba33cc
Discard changes to stubs/networkx/networkx/classes/graph.pyi
Avasam Aug 20, 2025
fc0104b
Discard changes to stubs/networkx/networkx/classes/multidigraph.pyi
Avasam Aug 20, 2025
764a6d2
Discard changes to stubs/networkx/networkx/classes/multigraph.pyi
Avasam Aug 20, 2025
2ba94b7
Update stubs/networkx/networkx/classes/reportviews.pyi
Avasam Aug 20, 2025
f43c212
Merge branch 'main' of https://github.com/python/typeshed into networ…
Avasam Aug 20, 2025
5bcdc2c
Update stubs/networkx/networkx/algorithms/approximation/traveling_sal…
Avasam Aug 20, 2025
53989c5
Merge branch 'main' of https://github.com/python/typeshed into networ…
Avasam Aug 20, 2025
7c89025
Merge branch 'main' into networkx-merge-from-python-type-stubs
Avasam Sep 26, 2025
26c884f
Merge branch 'main' of https://github.com/python/typeshed into networ…
Avasam Oct 3, 2025
c83ac31
Merge branch 'main' into networkx-merge-from-python-type-stubs
Avasam Nov 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions stubs/networkx/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,4 @@ networkx(\.algorithms)?(\.tree)?(\.mst)?\.SpanningTreeIterator\.Partition\._DT
networkx(\.algorithms)?(\.tree)?(\.branchings)?\.ArborescenceIterator\.Partition\._DT

# variable differs from runtime type abc.ABCMeta
networkx.classes.reportviews.EdgeView.dataview
networkx.classes.reportviews.InEdgeView.dataview
networkx.classes.reportviews.OutEdgeView.dataview
networkx.classes.reportviews.OutMultiEdgeView.dataview
networkx\.classes\.reportviews\.\w*EdgeView\.dataview
4 changes: 4 additions & 0 deletions stubs/networkx/networkx/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Final

from networkx.algorithms import *
from networkx.classes import *
from networkx.classes import filters as filters
Expand All @@ -24,3 +26,5 @@ from . import (
relabel as relabel,
utils as utils,
)

__version__: Final[str]
1 change: 1 addition & 0 deletions stubs/networkx/networkx/algorithms/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ from networkx.algorithms.structuralholes import *
from networkx.algorithms.summarization import *
from networkx.algorithms.swap import *
from networkx.algorithms.time_dependent import *
from networkx.algorithms.tournament import is_tournament as is_tournament
from networkx.algorithms.traversal import *
from networkx.algorithms.tree.branchings import (
ArborescenceIterator as ArborescenceIterator,
Expand Down
6 changes: 4 additions & 2 deletions stubs/networkx/networkx/algorithms/approximation/clique.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from _typeshed import Incomplete

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable

__all__ = ["clique_removal", "max_clique", "large_clique_size", "maximum_independent_set"]

@_dispatchable
def maximum_independent_set(G: Graph[_Node]): ...
def maximum_independent_set(G: Graph[_Node]) -> set[Incomplete]: ...
@_dispatchable
def max_clique(G: Graph[_Node]): ...
def max_clique(G: Graph[_Node]) -> set[Incomplete]: ...
@_dispatchable
def clique_removal(G: Graph[_Node]): ...
@_dispatchable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ from numpy.random import RandomState
__all__ = ["average_clustering"]

@_dispatchable
def average_clustering(G: Graph[_Node], trials: int = 1000, seed: int | RandomState | None = None): ...
def average_clustering(G: Graph[_Node], trials: int = 1000, seed: int | RandomState | None = None) -> float: ...
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ def local_node_connectivity(G: Graph[_Node], source: _Node, target: _Node, cutof
@_dispatchable
def node_connectivity(G: Graph[_Node], s: _Node | None = None, t: _Node | None = None): ...
@_dispatchable
def all_pairs_node_connectivity(G: Graph[_Node], nbunch: Iterable[Incomplete] | None = None, cutoff: int | None = None): ...
def all_pairs_node_connectivity(
G: Graph[_Node], nbunch: Iterable[Incomplete] | None = None, cutoff: int | None = None
) -> dict[Incomplete, dict[Incomplete, Incomplete]]: ...
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from _typeshed import Incomplete

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable

__all__ = ["min_weighted_dominating_set", "min_edge_dominating_set"]

@_dispatchable
def min_weighted_dominating_set(G: Graph[_Node], weight: str | None = None): ...
def min_weighted_dominating_set(G: Graph[_Node], weight: str | None = None) -> set[Incomplete]: ...
@_dispatchable
def min_edge_dominating_set(G: Graph[_Node]): ...
def min_edge_dominating_set(G: Graph[_Node]) -> set[Incomplete]: ...
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from _typeshed import Incomplete
from collections import defaultdict

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable

__all__ = ["k_components"]

@_dispatchable
def k_components(G: Graph[_Node], min_density: float = 0.95): ...
def k_components(G: Graph[_Node], min_density: float = 0.95) -> defaultdict[Incomplete, list[Incomplete]]: ...
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from _typeshed import Incomplete

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable

__all__ = ["min_maximal_matching"]

@_dispatchable
def min_maximal_matching(G: Graph[_Node]): ...
def min_maximal_matching(G: Graph[_Node]) -> set[Incomplete]: ...
6 changes: 5 additions & 1 deletion stubs/networkx/networkx/algorithms/approximation/maxcut.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,5 +13,8 @@ def randomized_partitioning(
): ...
@_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,
): ...
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from _typeshed import Incomplete
from collections.abc import Callable
from _typeshed import Incomplete, SupportsLenAndGetItem
from collections.abc import Callable, Iterable, Mapping
from typing import Literal, TypeVar

from networkx.classes.digraph import DiGraph
from networkx.classes.graph import Graph, _Node
Expand All @@ -14,9 +15,12 @@ __all__ = [
"simulated_annealing_tsp",
"threshold_accepting_tsp",
]
_SupportsLenAndGetItemT = TypeVar("_SupportsLenAndGetItemT", bound=SupportsLenAndGetItem[Incomplete])

def swap_two_nodes(soln: _SupportsLenAndGetItemT, seed) -> _SupportsLenAndGetItemT: ...
def move_one_node(soln: _SupportsLenAndGetItemT, seed) -> _SupportsLenAndGetItemT: ...
@_dispatchable
def christofides(G: Graph[_Node], weight: str | None = "weight", tree: Graph[_Node] | None = None): ...
def christofides(G: Graph[_Node], weight: str | None = "weight", tree: Graph[_Node] | None = None) -> list[Incomplete]: ...
@_dispatchable
def traveling_salesman_problem(
G: Graph[_Node],
Expand All @@ -25,12 +29,16 @@ def traveling_salesman_problem(
cycle: bool = True,
method: Callable[..., Incomplete] | None = None,
**kwargs,
): ...
) -> list[Incomplete]: ...
@_dispatchable
def asadpour_atsp(
G: DiGraph[_Node], weight: str | None = "weight", seed: int | RandomState | None = None, source: str | None = None
): ...
@_dispatchable
def held_karp_ascent(G: Graph[Incomplete], weight="weight"): ...
@_dispatchable
def spanning_tree_distribution(G: Graph[Incomplete], z: Mapping[Incomplete, Incomplete]) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def greedy_tsp(G: Graph[_Node], weight: str | None = "weight", source=None): ...
@_dispatchable
def simulated_annealing_tsp(
Expand All @@ -48,7 +56,7 @@ def simulated_annealing_tsp(
@_dispatchable
def threshold_accepting_tsp(
G: Graph[_Node],
init_cycle,
init_cycle: Literal["greedy"] | Iterable[Incomplete],
weight: str | None = "weight",
source=None,
threshold: int | None = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ class MinDegreeHeuristic:

def __init__(self, graph) -> None: ...
def best_node(self, graph): ...

def min_fill_in_heuristic(graph) -> Incomplete | None: ...
@_dispatchable
def treewidth_decomp(G: Graph[Incomplete], heuristic=...) -> tuple[int, Graph[Incomplete]]: ...
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from _typeshed import Incomplete

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable

__all__ = ["min_weighted_vertex_cover"]

@_dispatchable
def min_weighted_vertex_cover(G: Graph[_Node], weight: str | None = None): ...
def min_weighted_vertex_cover(G: Graph[_Node], weight: str | None = None) -> set[Incomplete]: ...
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from _typeshed import Incomplete
from collections.abc import Iterable
from typing import Literal

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
Expand All @@ -8,5 +9,9 @@ __all__ = ["average_degree_connectivity"]

@_dispatchable
def average_degree_connectivity(
G: Graph[_Node], source="in+out", target="in+out", nodes: Iterable[Incomplete] | None = None, weight: str | None = None
): ...
G: Graph[_Node],
source: Literal["in+out", "out", "in"] = "in+out",
target: Literal["in+out", "out", "in"] = "in+out",
nodes: Iterable[Incomplete] | None = None,
weight: str | None = None,
) -> dict[Incomplete, int | float]: ...
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ __all__ = [
@_dispatchable
def degree_assortativity_coefficient(
G: Graph[_Node], x: str = "out", y: str = "in", weight: str | None = None, nodes: Iterable[Incomplete] | None = None
): ...
) -> float: ...
@_dispatchable
def degree_pearson_correlation_coefficient(
G: Graph[_Node], x: str = "out", y: str = "in", weight: str | None = None, nodes: Iterable[Incomplete] | None = None
): ...
) -> float: ...
@_dispatchable
def attribute_assortativity_coefficient(G: Graph[_Node], attribute: str, nodes: Iterable[Incomplete] | None = None): ...
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): ...
def numeric_assortativity_coefficient(G: Graph[_Node], attribute: str, nodes: Iterable[Incomplete] | None = None) -> float: ...
def attribute_ac(M) -> float: ...
6 changes: 3 additions & 3 deletions stubs/networkx/networkx/algorithms/assortativity/mixing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ __all__ = ["attribute_mixing_matrix", "attribute_mixing_dict", "degree_mixing_ma
@_dispatchable
def attribute_mixing_dict(
G: Graph[_Node], attribute: str, nodes: Iterable[Incomplete] | None = None, normalized: bool = False
): ...
) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def attribute_mixing_matrix(
G: Graph[_Node],
Expand All @@ -21,7 +21,7 @@ def attribute_mixing_matrix(
@_dispatchable
def degree_mixing_dict(
G: Graph[_Node], x: str = "out", y: str = "in", weight: str | None = None, nodes=None, normalized: bool = False
): ...
) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def degree_mixing_matrix(
G: Graph[_Node],
Expand All @@ -33,4 +33,4 @@ def degree_mixing_matrix(
mapping: SupportsGetItem[Incomplete, Incomplete] | None = None,
): ...
@_dispatchable
def mixing_dict(xy, normalized: bool = False): ...
def mixing_dict(xy, normalized: bool = False) -> dict[Incomplete, Incomplete]: ...
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def average_neighbor_degree(
target: str | None = "out",
nodes: Iterable[Incomplete] | None = None,
weight: str | None = None,
): ...
) -> dict[Incomplete, Incomplete]: ...
6 changes: 5 additions & 1 deletion stubs/networkx/networkx/algorithms/asteroidal.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from _typeshed import Incomplete

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable

__all__ = ["is_at_free", "find_asteroidal_triple"]

@_dispatchable
def find_asteroidal_triple(G: Graph[_Node]): ...
def find_asteroidal_triple(G: Graph[_Node]) -> list[Incomplete] | None: ...
@_dispatchable
def is_at_free(G: Graph[_Node]) -> bool: ...
@_dispatchable
def create_component_structure(G: Graph[Incomplete]) -> dict[Incomplete, Incomplete]: ...
8 changes: 4 additions & 4 deletions stubs/networkx/networkx/algorithms/bipartite/basic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ from networkx.utils.backends import _dispatchable
__all__ = ["is_bipartite", "is_bipartite_node_set", "color", "sets", "density", "degrees"]

@_dispatchable
def color(G: Graph[_Node]): ...
def color(G: Graph[_Node]) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def is_bipartite(G: Graph[_Node]) -> bool: ...
@_dispatchable
def is_bipartite_node_set(G: Graph[_Node], nodes: Iterable[Incomplete]) -> bool: ...
@_dispatchable
def sets(G: Graph[_Node], top_nodes: Iterable[Incomplete] | None = None): ...
def sets(G: Graph[_Node], top_nodes: Iterable[Incomplete] | None = None) -> tuple[set[Incomplete], set[Incomplete]]: ...
@_dispatchable
def density(B: Graph[_Node], nodes): ...
def density(B: Graph[_Node], nodes) -> float: ...
@_dispatchable
def degrees(B: Graph[_Node], nodes, weight: str | None = None): ...
def degrees(B: Graph[_Node], nodes, weight: str | None = None) -> tuple[Incomplete, Incomplete]: ...
8 changes: 5 additions & 3 deletions stubs/networkx/networkx/algorithms/bipartite/centrality.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from _typeshed import Incomplete

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable

__all__ = ["degree_centrality", "betweenness_centrality", "closeness_centrality"]

@_dispatchable
def degree_centrality(G: Graph[_Node], nodes): ...
def degree_centrality(G: Graph[_Node], nodes) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def betweenness_centrality(G: Graph[_Node], nodes): ...
def betweenness_centrality(G: Graph[_Node], nodes) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def closeness_centrality(G: Graph[_Node], nodes, normalized: bool | None = True): ...
def closeness_centrality(G: Graph[_Node], nodes, normalized: bool | None = True) -> dict[Incomplete, Incomplete]: ...
16 changes: 12 additions & 4 deletions stubs/networkx/networkx/algorithms/bipartite/cluster.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
from _typeshed import Incomplete
from collections.abc import Iterable
from collections.abc import Callable, Iterable

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable

__all__ = ["clustering", "average_clustering", "latapy_clustering", "robins_alexander_clustering"]

def cc_dot(nu, nv) -> float: ...
def cc_max(nu, nv) -> float: ...
def cc_min(nu, nv) -> float: ...

modes: dict[str, Callable[[Incomplete, Incomplete], float]]

@_dispatchable
def latapy_clustering(G: Graph[_Node], nodes: Iterable[Incomplete] | None = None, mode: str = "dot"): ...
def latapy_clustering(
G: Graph[_Node], nodes: Iterable[Incomplete] | None = None, mode: str = "dot"
) -> dict[Incomplete, Incomplete]: ...

clustering = latapy_clustering

@_dispatchable
def average_clustering(G: Graph[_Node], nodes: Iterable[Incomplete] | None = None, mode: str = "dot"): ...
def average_clustering(G: Graph[_Node], nodes: Iterable[Incomplete] | None = None, mode: str = "dot") -> float: ...
@_dispatchable
def robins_alexander_clustering(G: Graph[_Node]): ...
def robins_alexander_clustering(G: Graph[_Node]) -> float: ...
2 changes: 1 addition & 1 deletion stubs/networkx/networkx/algorithms/bipartite/covering.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ from networkx.utils.backends import _dispatchable
__all__ = ["min_edge_cover"]

@_dispatchable
def min_edge_cover(G: Graph[_Node], matching_algorithm: Callable[..., Incomplete] | None = None): ...
def min_edge_cover(G: Graph[_Node], matching_algorithm: Callable[..., Incomplete] | None = None) -> set[Incomplete]: ...
19 changes: 14 additions & 5 deletions stubs/networkx/networkx/algorithms/bipartite/edgelist.pyi
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
from _typeshed import Incomplete
from collections.abc import Generator
from collections.abc import Generator, Iterable

from networkx.classes.graph import Graph, _Node
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[Incomplete],
path,
comments: str = "#",
delimiter: str = " ",
data: bool | Iterable[Incomplete] = True,
encoding: str = "utf-8",
) -> None: ...
@_dispatchable
def generate_edgelist(G, delimiter: str = " ", data: bool = True) -> Generator[Incomplete, None, None]: ...
def generate_edgelist(
G: Graph[Incomplete], delimiter: str = " ", data: bool | Iterable[Incomplete] = True
) -> Generator[str, None, None]: ...
@_dispatchable
def parse_edgelist(
lines,
comments: str | None = "#",
delimiter: str | None = None,
create_using: Graph[_Node] | None = None,
nodetype=None,
data=True,
data: bool | Iterable[Incomplete] = True,
): ...
@_dispatchable
def read_edgelist(
Expand All @@ -26,7 +35,7 @@ def read_edgelist(
delimiter: str | None = None,
create_using=None,
nodetype=None,
data=True,
data: bool | Iterable[Incomplete] = True,
edgetype=None,
encoding: str | None = "utf-8",
): ...
Loading
Loading