[networkx] Update usages of SupportsGetItem that should be more restrictive (#14795)

This commit is contained in:
Avasam
2025-12-19 12:45:15 -05:00
committed by GitHub
parent 1f696b82bd
commit 3c2dbb1fde
9 changed files with 31 additions and 26 deletions
@@ -1,5 +1,5 @@
from _typeshed import Incomplete, SupportsGetItem
from collections.abc import Iterable
from _typeshed import Incomplete
from collections.abc import Iterable, Mapping
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
@@ -15,7 +15,7 @@ def attribute_mixing_matrix(
G: Graph[_Node],
attribute: str,
nodes: Iterable[Incomplete] | None = None,
mapping: SupportsGetItem[Incomplete, Incomplete] | None = None,
mapping: Mapping[Incomplete, Incomplete] | None = None,
normalized: bool = True,
): ...
@_dispatchable
@@ -30,7 +30,7 @@ def degree_mixing_matrix(
weight: str | None = None,
nodes: Iterable[Incomplete] | None = None,
normalized: bool = True,
mapping: SupportsGetItem[Incomplete, Incomplete] | None = None,
mapping: Mapping[Incomplete, Incomplete] | None = None,
): ...
@_dispatchable
def mixing_dict(xy, normalized: bool = False) -> dict[Incomplete, Incomplete]: ...
@@ -1,5 +1,5 @@
from _typeshed import Incomplete, SupportsGetItem
from collections.abc import Iterable
from _typeshed import Incomplete
from collections.abc import Iterable, Mapping
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
@@ -12,7 +12,7 @@ def hopcroft_karp_matching(G: Graph[_Node], top_nodes: Iterable[_Node] | None =
def eppstein_matching(G: Graph[_Node], top_nodes: Iterable[Incomplete] | None = None) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def to_vertex_cover(
G: Graph[_Node], matching: SupportsGetItem[Incomplete, Incomplete], top_nodes: Iterable[Incomplete] | None = None
G: Graph[_Node], matching: Mapping[Incomplete, Incomplete], top_nodes: Iterable[Incomplete] | None = None
): ...
maximum_matching = hopcroft_karp_matching
@@ -1,4 +1,4 @@
from _typeshed import Incomplete, SupportsGetItem
from _typeshed import Incomplete, SupportsKeysAndGetItem
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
@@ -13,7 +13,7 @@ def closeness_centrality(
def incremental_closeness_centrality(
G: Graph[_Node],
edge: tuple[Incomplete],
prev_cc: SupportsGetItem[Incomplete, Incomplete] | None = None,
prev_cc: SupportsKeysAndGetItem[Incomplete, Incomplete] | None = None,
insertion: bool | None = True,
wf_improved: bool | None = True,
) -> dict[_Node, float]: ...
@@ -1,4 +1,5 @@
from _typeshed import Incomplete, SupportsGetItem
from _typeshed import Incomplete
from collections.abc import Mapping
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
@@ -10,7 +11,7 @@ def eigenvector_centrality(
G: Graph[_Node],
max_iter: int | None = 100,
tol: float | None = 1e-06,
nstart: SupportsGetItem[Incomplete, Incomplete] | None = None,
nstart: Mapping[Incomplete, Incomplete] | None = None,
weight: str | None = None,
) -> dict[Incomplete, float]: ...
@_dispatchable
@@ -1,4 +1,5 @@
from _typeshed import Incomplete, SupportsGetItem
from _typeshed import ConvertibleToFloat, Incomplete, SupportsItemAccess
from collections.abc import Iterable, Mapping
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
@@ -9,10 +10,10 @@ __all__ = ["katz_centrality", "katz_centrality_numpy"]
def katz_centrality(
G: Graph[_Node],
alpha: float | None = 0.1,
beta: float | SupportsGetItem[Incomplete, Incomplete] | None = 1.0,
beta: ConvertibleToFloat | Iterable[Incomplete] | None = 1.0,
max_iter: int | None = 1000,
tol: float | None = 1e-06,
nstart: SupportsGetItem[Incomplete, Incomplete] | None = None,
nstart: SupportsItemAccess[Incomplete, Incomplete] | None = None,
normalized: bool | None = True,
weight: str | None = None,
) -> dict[Incomplete, Incomplete]: ...
@@ -20,7 +21,7 @@ def katz_centrality(
def katz_centrality_numpy(
G: Graph[_Node],
alpha: float = 0.1,
beta: float | SupportsGetItem[Incomplete, Incomplete] | None = 1.0,
beta: float | Mapping[Incomplete, Incomplete] | None = 1.0,
normalized: bool = True,
weight: str | None = None,
) -> dict[Incomplete, Incomplete]: ...
@@ -1,4 +1,5 @@
from _typeshed import Incomplete, SupportsGetItem
from _typeshed import Incomplete
from collections.abc import Mapping
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
@@ -9,6 +10,6 @@ __all__ = ["percolation_centrality"]
def percolation_centrality(
G: Graph[_Node],
attribute: str | None = "percolation",
states: SupportsGetItem[Incomplete, Incomplete] | None = None,
states: Mapping[Incomplete, Incomplete] | None = None,
weight: str | None = None,
) -> dict[Incomplete, float]: ...
@@ -1,4 +1,5 @@
from _typeshed import Incomplete, SupportsGetItem
from _typeshed import Incomplete
from collections.abc import Mapping
from networkx.classes.digraph import DiGraph
from networkx.classes.graph import _Node
@@ -12,7 +13,7 @@ def global_reaching_centrality(G: DiGraph[_Node], weight: str | None = None, nor
def local_reaching_centrality(
G: DiGraph[_Node],
v: _Node,
paths: SupportsGetItem[Incomplete, Incomplete] | None = None,
paths: Mapping[Incomplete, Incomplete] | None = None,
weight: str | None = None,
normalized: bool | None = True,
) -> float: ...
+6 -5
View File
@@ -1,4 +1,5 @@
from _typeshed import Incomplete, SupportsGetItem
from _typeshed import Incomplete
from collections.abc import Mapping
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
@@ -8,13 +9,13 @@ __all__ = ["core_number", "k_core", "k_shell", "k_crust", "k_corona", "k_truss",
@_dispatchable
def core_number(G: Graph[_Node]) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def k_core(G: Graph[_Node], k: int | None = None, core_number: SupportsGetItem[Incomplete, Incomplete] | None = None): ...
def k_core(G: Graph[_Node], k: int | None = None, core_number: Mapping[Incomplete, Incomplete] | None = None): ...
@_dispatchable
def k_shell(G: Graph[_Node], k: int | None = None, core_number: SupportsGetItem[Incomplete, Incomplete] | None = None): ...
def k_shell(G: Graph[_Node], k: int | None = None, core_number: Mapping[Incomplete, Incomplete] | None = None): ...
@_dispatchable
def k_crust(G: Graph[_Node], k: int | None = None, core_number: SupportsGetItem[Incomplete, Incomplete] | None = None): ...
def k_crust(G: Graph[_Node], k: int | None = None, core_number: Mapping[Incomplete, Incomplete] | None = None): ...
@_dispatchable
def k_corona(G: Graph[_Node], k: int, core_number: SupportsGetItem[Incomplete, Incomplete] | None = None): ...
def k_corona(G: Graph[_Node], k: int | None, core_number: Mapping[Incomplete, Incomplete] | None = None): ...
@_dispatchable
def k_truss(G: Graph[_Node], k: int): ...
@_dispatchable
@@ -1,4 +1,4 @@
from _typeshed import Incomplete, SupportsGetItem
from _typeshed import Incomplete, SupportsItemAccess
from collections.abc import Callable, Generator
from networkx.classes.graph import Graph, _Node
@@ -117,7 +117,7 @@ def generate_random_paths(
G: Graph[_Node],
sample_size: int,
path_length: int = 5,
index_map: SupportsGetItem[Incomplete, Incomplete] | None = None,
index_map: SupportsItemAccess[Incomplete, Incomplete] | None = None,
weight: str | None = "weight",
seed: int | RandomState | None = None,
*,