Skip to content
Merged
Changes from 1 commit
Commits
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
19 changes: 12 additions & 7 deletions stubs/networkx/networkx/algorithms/approximation/treewidth.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use a protocol for graph_dict. Unfortunately, _typeshed.SupportsLenAndGetItem is not generic over the item type, but collections.abc.Mapping would be an improvement for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out. Updated

@_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]]]: ...
Loading