Skip to content

Commit db8be49

Browse files
committed
networkx: Update usages of SupportsGetItem that should be more restrictive
1 parent fb21402 commit db8be49

File tree

9 files changed

+31
-26
lines changed

9 files changed

+31
-26
lines changed

stubs/networkx/networkx/algorithms/assortativity/mixing.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from _typeshed import Incomplete, SupportsGetItem
2-
from collections.abc import Iterable
1+
from _typeshed import Incomplete
2+
from collections.abc import Iterable, Mapping
33

44
from networkx.classes.graph import Graph, _Node
55
from networkx.utils.backends import _dispatchable
@@ -15,7 +15,7 @@ def attribute_mixing_matrix(
1515
G: Graph[_Node],
1616
attribute: str,
1717
nodes: Iterable[Incomplete] | None = None,
18-
mapping: SupportsGetItem[Incomplete, Incomplete] | None = None,
18+
mapping: Mapping[Incomplete, Incomplete] | None = None,
1919
normalized: bool = True,
2020
): ...
2121
@_dispatchable
@@ -30,7 +30,7 @@ def degree_mixing_matrix(
3030
weight: str | None = None,
3131
nodes: Iterable[Incomplete] | None = None,
3232
normalized: bool = True,
33-
mapping: SupportsGetItem[Incomplete, Incomplete] | None = None,
33+
mapping: Mapping[Incomplete, Incomplete] | None = None,
3434
): ...
3535
@_dispatchable
3636
def mixing_dict(xy, normalized: bool = False) -> dict[Incomplete, Incomplete]: ...

stubs/networkx/networkx/algorithms/bipartite/matching.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from _typeshed import Incomplete, SupportsGetItem
2-
from collections.abc import Iterable
1+
from _typeshed import Incomplete
2+
from collections.abc import Iterable, Mapping
33

44
from networkx.classes.graph import Graph, _Node
55
from networkx.utils.backends import _dispatchable
@@ -12,7 +12,7 @@ def hopcroft_karp_matching(G: Graph[_Node], top_nodes: Iterable[_Node] | None =
1212
def eppstein_matching(G: Graph[_Node], top_nodes: Iterable[Incomplete] | None = None) -> dict[Incomplete, Incomplete]: ...
1313
@_dispatchable
1414
def to_vertex_cover(
15-
G: Graph[_Node], matching: SupportsGetItem[Incomplete, Incomplete], top_nodes: Iterable[Incomplete] | None = None
15+
G: Graph[_Node], matching: Mapping[Incomplete, Incomplete], top_nodes: Iterable[Incomplete] | None = None
1616
): ...
1717

1818
maximum_matching = hopcroft_karp_matching

stubs/networkx/networkx/algorithms/centrality/closeness.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import Incomplete, SupportsGetItem
1+
from _typeshed import Incomplete, SupportsKeysAndGetItem
22

33
from networkx.classes.graph import Graph, _Node
44
from networkx.utils.backends import _dispatchable
@@ -13,7 +13,7 @@ def closeness_centrality(
1313
def incremental_closeness_centrality(
1414
G: Graph[_Node],
1515
edge: tuple[Incomplete],
16-
prev_cc: SupportsGetItem[Incomplete, Incomplete] | None = None,
16+
prev_cc: SupportsKeysAndGetItem[Incomplete, Incomplete] | None = None,
1717
insertion: bool | None = True,
1818
wf_improved: bool | None = True,
1919
) -> dict[_Node, float]: ...

stubs/networkx/networkx/algorithms/centrality/eigenvector.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from _typeshed import Incomplete, SupportsGetItem
1+
from _typeshed import Incomplete
2+
from collections.abc import Mapping
23

34
from networkx.classes.graph import Graph, _Node
45
from networkx.utils.backends import _dispatchable
@@ -10,7 +11,7 @@ def eigenvector_centrality(
1011
G: Graph[_Node],
1112
max_iter: int | None = 100,
1213
tol: float | None = 1e-06,
13-
nstart: SupportsGetItem[Incomplete, Incomplete] | None = None,
14+
nstart: Mapping[Incomplete, Incomplete] | None = None,
1415
weight: str | None = None,
1516
) -> dict[Incomplete, float]: ...
1617
@_dispatchable
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from _typeshed import Incomplete, SupportsGetItem
1+
from _typeshed import ConvertibleToFloat, Incomplete, SupportsItemAccess
2+
from collections.abc import Iterable, Mapping
23

34
from networkx.classes.graph import Graph, _Node
45
from networkx.utils.backends import _dispatchable
@@ -9,18 +10,18 @@ __all__ = ["katz_centrality", "katz_centrality_numpy"]
910
def katz_centrality(
1011
G: Graph[_Node],
1112
alpha: float | None = 0.1,
12-
beta: float | SupportsGetItem[Incomplete, Incomplete] | None = 1.0,
13+
beta: ConvertibleToFloat | Iterable[Incomplete] | None = 1.0,
1314
max_iter: int | None = 1000,
1415
tol: float | None = 1e-06,
15-
nstart: SupportsGetItem[Incomplete, Incomplete] | None = None,
16+
nstart: SupportsItemAccess[Incomplete, Incomplete] | None = None,
1617
normalized: bool | None = True,
1718
weight: str | None = None,
1819
) -> dict[Incomplete, Incomplete]: ...
1920
@_dispatchable
2021
def katz_centrality_numpy(
2122
G: Graph[_Node],
2223
alpha: float = 0.1,
23-
beta: float | SupportsGetItem[Incomplete, Incomplete] | None = 1.0,
24+
beta: float | Mapping[Incomplete, Incomplete] | None = 1.0,
2425
normalized: bool = True,
2526
weight: str | None = None,
2627
) -> dict[Incomplete, Incomplete]: ...

stubs/networkx/networkx/algorithms/centrality/percolation.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from _typeshed import Incomplete, SupportsGetItem
1+
from _typeshed import Incomplete
2+
from collections.abc import Mapping
23

34
from networkx.classes.graph import Graph, _Node
45
from networkx.utils.backends import _dispatchable
@@ -9,6 +10,6 @@ __all__ = ["percolation_centrality"]
910
def percolation_centrality(
1011
G: Graph[_Node],
1112
attribute: str | None = "percolation",
12-
states: SupportsGetItem[Incomplete, Incomplete] | None = None,
13+
states: Mapping[Incomplete, Incomplete] | None = None,
1314
weight: str | None = None,
1415
) -> dict[Incomplete, float]: ...

stubs/networkx/networkx/algorithms/centrality/reaching.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from _typeshed import Incomplete, SupportsGetItem
1+
from _typeshed import Incomplete
2+
from collections.abc import Mapping
23

34
from networkx.classes.digraph import DiGraph
45
from networkx.classes.graph import _Node
@@ -12,7 +13,7 @@ def global_reaching_centrality(G: DiGraph[_Node], weight: str | None = None, nor
1213
def local_reaching_centrality(
1314
G: DiGraph[_Node],
1415
v: _Node,
15-
paths: SupportsGetItem[Incomplete, Incomplete] | None = None,
16+
paths: Mapping[Incomplete, Incomplete] | None = None,
1617
weight: str | None = None,
1718
normalized: bool | None = True,
1819
) -> float: ...

stubs/networkx/networkx/algorithms/core.pyi

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from _typeshed import Incomplete, SupportsGetItem
1+
from _typeshed import Incomplete
2+
from collections.abc import Mapping
23

34
from networkx.classes.graph import Graph, _Node
45
from networkx.utils.backends import _dispatchable
@@ -8,13 +9,13 @@ __all__ = ["core_number", "k_core", "k_shell", "k_crust", "k_corona", "k_truss",
89
@_dispatchable
910
def core_number(G: Graph[_Node]) -> dict[Incomplete, Incomplete]: ...
1011
@_dispatchable
11-
def k_core(G: Graph[_Node], k: int | None = None, core_number: SupportsGetItem[Incomplete, Incomplete] | None = None): ...
12+
def k_core(G: Graph[_Node], k: int | None = None, core_number: Mapping[Incomplete, Incomplete] | None = None): ...
1213
@_dispatchable
13-
def k_shell(G: Graph[_Node], k: int | None = None, core_number: SupportsGetItem[Incomplete, Incomplete] | None = None): ...
14+
def k_shell(G: Graph[_Node], k: int | None = None, core_number: Mapping[Incomplete, Incomplete] | None = None): ...
1415
@_dispatchable
15-
def k_crust(G: Graph[_Node], k: int | None = None, core_number: SupportsGetItem[Incomplete, Incomplete] | None = None): ...
16+
def k_crust(G: Graph[_Node], k: int | None = None, core_number: Mapping[Incomplete, Incomplete] | None = None): ...
1617
@_dispatchable
17-
def k_corona(G: Graph[_Node], k: int, core_number: SupportsGetItem[Incomplete, Incomplete] | None = None): ...
18+
def k_corona(G: Graph[_Node], k: int | None, core_number: Mapping[Incomplete, Incomplete] | None = None): ...
1819
@_dispatchable
1920
def k_truss(G: Graph[_Node], k: int): ...
2021
@_dispatchable

stubs/networkx/networkx/algorithms/similarity.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import Incomplete, SupportsGetItem
1+
from _typeshed import Incomplete, SupportsItemAccess
22
from collections.abc import Callable, Generator
33

44
from networkx.classes.graph import Graph, _Node
@@ -101,7 +101,7 @@ def generate_random_paths(
101101
G: Graph[_Node],
102102
sample_size: int,
103103
path_length: int = 5,
104-
index_map: SupportsGetItem[Incomplete, Incomplete] | None = None,
104+
index_map: SupportsItemAccess[Incomplete, Incomplete] | None = None,
105105
weight: str | None = "weight",
106106
seed: int | RandomState | None = None,
107107
*,

0 commit comments

Comments
 (0)