From 65b8a85e4b775d5465e7fdb7382c181fb7efa958 Mon Sep 17 00:00:00 2001 From: "Rickey K. Liang" Date: Wed, 5 Nov 2025 17:46:59 +0100 Subject: [PATCH] Add annotations to `networkx.algorithms.approximation.treewidth` (#14983) --- .../algorithms/approximation/treewidth.pyi | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi b/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi index 00f95e3eb..6a9f9afe2 100644 --- a/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi +++ b/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi @@ -1,4 +1,6 @@ from _typeshed import Incomplete +from collections.abc import Callable, Mapping +from typing import Generic from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable @@ -6,16 +8,18 @@ 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: Mapping[_Node, set[_Node]]) -> _Node | None: ... -def min_fill_in_heuristic(graph_dict) -> Incomplete | None: ... +def min_fill_in_heuristic(graph_dict: Mapping[_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]]]: ...