Skip to content

Commit 19c256a

Browse files
committed
fix: fix lots of mypy typing warnings
1 parent f4cfb26 commit 19c256a

File tree

10 files changed

+192
-293
lines changed

10 files changed

+192
-293
lines changed

src/codegen/functions.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ igraph_maximal_cliques_callback:
1313
igraph_community_leading_eigenvector:
1414
IGNORE: PythonCTypes
1515

16-
igraph_subisomorphic_function_vf2:
17-
IGNORE: PythonCTypes
18-
1916
igraph_eigen_adjacency:
2017
IGNORE: PythonCTypes
2118

src/codegen/internal_enums.py.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from enum import IntEnum
4-
from typing import Any, ClassVar
4+
from typing import Any
55

66

77
class Loops(IntEnum):

src/codegen/run.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,14 @@ def process_enum(fp: TextIO, spec) -> Optional[str]: # noqa: C901
220220

221221
for key, value_int_or_str in EXTRA_ENUM_MEMBERS.get(name, ()):
222222
if isinstance(value_int_or_str, str):
223-
value_int = all_members[value_int_or_str.lower()]
223+
value_str = all_members[value_int_or_str.lower()]
224224
aliased_to = value_int_or_str
225225
else:
226-
value_int = value_int_or_str
226+
value_str = str(value_int_or_str)
227227
aliased_to = key
228-
fp.write(f" {key} = {value_int}\n")
228+
fp.write(f" {key} = {value_str}\n")
229229
all_members[key.lower()] = aliased_to
230230

231-
fp.write("\n")
232-
fp.write(f" _string_map: ClassVar[dict[str, {name}]]\n")
233231
fp.write("\n")
234232
fp.write(" @classmethod\n")
235233
fp.write(" def from_(cls, value: Any):\n")
@@ -244,14 +242,14 @@ def process_enum(fp: TextIO, spec) -> Optional[str]: # noqa: C901
244242
fp.write(" return cls(value)\n")
245243
fp.write(" else:\n")
246244
fp.write(" try:\n")
247-
fp.write(" return cls._string_map[value]\n")
245+
fp.write(f" return _{name}_string_map[value]\n")
248246
fp.write(" except KeyError:\n")
249247
fp.write(
250248
f' raise ValueError(f"{{value!r}} cannot be '
251249
f'converted to {name}") from None\n'
252250
)
253251
fp.write("\n\n")
254-
fp.write(f"{name}._string_map = {{\n")
252+
fp.write(f"_{name}_string_map: dict[str, {name}] = {{\n")
255253
for key in sorted(all_members.keys()):
256254
fp.write(f" {key!r}: {name}.{all_members[key]},\n")
257255
fp.write("}\n")

src/igraph_ctypes/_internal/attributes/map.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def set(
8383
value for all vertices or edges.
8484
"""
8585
length = self._common_length_of_values
86+
avl: AttributeValueList[T]
8687

8788
if isinstance(value, (bytes, str)):
8889
# strings and bytes are iterable but they are treated as if not

src/igraph_ctypes/_internal/attributes/value_list.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
)
4343

4444

45-
class AttributeValueList(Sequence[T | None]):
45+
class AttributeValueList(Sequence[T]):
4646
"""List-like data structure that stores the values of a vertex or an edge
4747
attribute for every vertex and edge in the graph, while supporting
4848
NumPy-style fancy indexing operations.
@@ -281,7 +281,7 @@ def __delitem__(self, index: IndexLike) -> None: # noqa: C901
281281
raise RuntimeError("cannot delete items from a fixed-length list")
282282

283283
@overload
284-
def __getitem__(self, index: IntLike) -> T | None: ...
284+
def __getitem__(self, index: IntLike) -> T: ...
285285

286286
@overload
287287
def __getitem__(
@@ -307,17 +307,18 @@ def __getitem__(self, index: IndexLike):
307307

308308
elif isinstance(index, Sequence):
309309
return self.__class__(
310-
self._items[index,],
310+
self._items[index,], # type: ignore
311311
type=self._type,
312-
_wrap=True, # type: ignore
312+
_wrap=True,
313313
)
314314

315315
elif isinstance(index, np.ndarray):
316316
return self._items[index]
317317

318318
self._raise_invalid_index_error()
319319

320-
def __iter__(self) -> Iterable[T]:
320+
def __iter__(self):
321+
# No return value typing here to make mypy happy
321322
return iter(self._items)
322323

323324
def __len__(self) -> int:
@@ -381,7 +382,7 @@ def __setitem__( # noqa: C901
381382
value = value.ravel()
382383
if isinstance(value, Iterator):
383384
value = list(value)
384-
self._items[index,] = value
385+
self._items[index,] = value # type: ignore
385386

386387
else:
387388
self._raise_invalid_index_error()
@@ -398,6 +399,7 @@ def _extend_length_by(self, n: int) -> None:
398399
# We do not have enough space pre-allocated, find the nearest
399400
# power of two that will suffice
400401
new_length = 2 ** int(np.ceil(np.log2(target_length)))
402+
default_value: Any
401403
if self._type is AttributeType.BOOLEAN:
402404
default_value = False
403405
elif self._type is AttributeType.NUMERIC:

src/igraph_ctypes/_internal/conversion.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@
151151
"vertexlike_to_igraph_integer_t",
152152
"vertex_pairs_to_igraph_vector_int_t",
153153
"vertex_selector_to_igraph_vs_t",
154-
"vertex_colors_to_igraph_vector_t",
155-
"vertex_colors_to_igraph_vector_t_view",
154+
"vertex_colors_to_igraph_vector_int_t",
155+
"vertex_colors_to_igraph_vector_int_t_view",
156156
"vertex_qtys_to_igraph_vector_t",
157157
"vertex_qtys_to_igraph_vector_t_view",
158158
"vertex_weights_to_igraph_vector_t",
@@ -742,12 +742,14 @@ def vertex_selector_to_igraph_vs_t(
742742
return _VertexSelector.create_with(igraph_vs_1, index)
743743

744744

745-
def vertex_colors_to_igraph_vector_t(colors: Iterable[int], graph: Graph) -> _VectorInt:
745+
def vertex_colors_to_igraph_vector_int_t(
746+
colors: Iterable[int], graph: Graph
747+
) -> _VectorInt:
746748
"""Converts a Python iterable of integers to a vector of vertex colors."""
747749
return iterable_to_igraph_vector_int_t(colors)
748750

749751

750-
def vertex_colors_to_igraph_vector_t_view(
752+
def vertex_colors_to_igraph_vector_int_t_view(
751753
colors: Iterable[int], graph: Graph
752754
) -> _VectorInt:
753755
"""Converts a Python iterable of integers to a vector of vertex colors,

0 commit comments

Comments
 (0)