From b0e730f7caf9da3833ae8f0c65073ba6d2f41fcf Mon Sep 17 00:00:00 2001 From: lkct Date: Wed, 5 Nov 2025 17:02:13 +0100 Subject: [PATCH 1/3] Fix stub for `networkx.algorithms.approximation.treewidth` --- .../algorithms/approximation/treewidth.pyi | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi b/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi index 00f95e3eb0cf..06348eda72b0 100644 --- a/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi +++ b/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi @@ -1,21 +1,26 @@ from _typeshed import Incomplete +from collections.abc import Callable +from typing import Generic + from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable __all__ = ["treewidth_min_degree", "treewidth_min_fill_in"] @_dispatchable -def treewidth_min_degree(G: Graph[_Node]): ... +def treewidth_min_degree(G: Graph[_Node]) -> tuple[int, Graph[frozenset[_Node]]]: ... @_dispatchable -def treewidth_min_fill_in(G: Graph[_Node]): ... +def treewidth_min_fill_in(G: Graph[_Node]) -> tuple[int, Graph[frozenset[_Node]]]: ... -class MinDegreeHeuristic: +class MinDegreeHeuristic(Generic[_Node]): count: Incomplete - def __init__(self, graph) -> None: ... - def best_node(self, graph): ... + def __init__(self, graph: Graph[_Node]) -> None: ... + def best_node(self, graph: dict[_Node, set[_Node]]) -> _Node | None: ... -def min_fill_in_heuristic(graph_dict) -> Incomplete | None: ... +def min_fill_in_heuristic(graph_dict: dict[_Node, set[_Node]]) -> _Node | None: ... @_dispatchable -def treewidth_decomp(G: Graph[_Node], heuristic=...) -> tuple[int, Graph[_Node]]: ... +def treewidth_decomp( + G: Graph[_Node], heuristic: Callable[[dict[_Node, set[_Node]]], _Node | None] = ... +) -> tuple[int, Graph[frozenset[_Node]]]: ... From 2e1d08ebfc970b478b50359a135a149c271a219b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 5 Nov 2025 16:09:20 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/networkx/networkx/algorithms/approximation/treewidth.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi b/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi index 06348eda72b0..7997f6f60b49 100644 --- a/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi +++ b/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi @@ -1,5 +1,4 @@ from _typeshed import Incomplete - from collections.abc import Callable from typing import Generic From 5181e7fae8518587eabca593b5500b99cf819fae Mon Sep 17 00:00:00 2001 From: lkct Date: Wed, 5 Nov 2025 17:21:32 +0100 Subject: [PATCH 3/3] Use Mapping for graph_dict --- .../networkx/algorithms/approximation/treewidth.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi b/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi index 7997f6f60b49..6a9f9afe2d39 100644 --- a/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi +++ b/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete -from collections.abc import Callable +from collections.abc import Callable, Mapping from typing import Generic from networkx.classes.graph import Graph, _Node @@ -16,9 +16,9 @@ class MinDegreeHeuristic(Generic[_Node]): count: Incomplete def __init__(self, graph: Graph[_Node]) -> None: ... - def best_node(self, graph: dict[_Node, set[_Node]]) -> _Node | None: ... + def best_node(self, graph: Mapping[_Node, set[_Node]]) -> _Node | None: ... -def min_fill_in_heuristic(graph_dict: dict[_Node, set[_Node]]) -> _Node | None: ... +def min_fill_in_heuristic(graph_dict: Mapping[_Node, set[_Node]]) -> _Node | None: ... @_dispatchable def treewidth_decomp( G: Graph[_Node], heuristic: Callable[[dict[_Node, set[_Node]]], _Node | None] = ...