Skip to content

Commit 71a4a5e

Browse files
committed
refactor: make use of Python 3.9 where list, set and dict are now subscriptable
1 parent bb40cc3 commit 71a4a5e

File tree

10 files changed

+188
-194
lines changed

10 files changed

+188
-194
lines changed

poetry.lock

Lines changed: 55 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pytest = "^7.2.1"
1515
pytest-cov = "^4.0.0"
1616
richbench = "^1.0.3"
1717
igraph = "^0.10.6"
18-
stimulus = { git = "https://github.com/igraph/stimulus.git", tag = "0.14.0" }
18+
stimulus = { git = "https://github.com/igraph/stimulus.git", tag = "0.14.1" }
1919

2020
[tool.poetry-dynamic-versioning]
2121
enable = true

src/codegen/internal_functions.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 ctypes import c_char_p, c_int
4-
from typing import Any, Iterable, List, Optional, Tuple, TYPE_CHECKING
4+
from typing import Any, Iterable, Optional, TYPE_CHECKING
55

66
from .conversion import * # noqa
77
from .enums import * # noqa

src/codegen/run.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
from pathlib import Path
44
from typing import (
55
Callable,
6-
Dict,
76
Iterable,
8-
List,
97
Optional,
108
Sequence,
119
TextIO,
12-
Tuple,
1310
Union,
1411
)
1512

@@ -140,7 +137,7 @@ def generate_enums( # noqa: C901
140137
"VitType": "VertexIteratorType",
141138
"VsType": "VertexSequenceType",
142139
}
143-
EXTRA_ENUM_MEMBERS: Dict[str, Sequence[Tuple[str, int]]] = {
140+
EXTRA_ENUM_MEMBERS: dict[str, Sequence[tuple[str, int]]] = {
144141
"Loops": [("IGNORE", 0)]
145142
}
146143

@@ -219,7 +216,7 @@ def process_enum(fp: TextIO, spec) -> Optional[str]: # noqa: C901
219216
fp.write("\n\n")
220217
return name
221218

222-
def process_file(outfp: TextIO, infp: TextIO) -> List[str]:
219+
def process_file(outfp: TextIO, infp: TextIO) -> list[str]:
223220
all_names = []
224221

225222
current_enum, in_enum = [], False

src/codegen/types.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ VERTEX_INDICES:
129129

130130
VERTEX_INDICES_LIST:
131131
PY_TYPE: Iterable[Iterable[VertexLike]]
132-
PY_RETURN_TYPE: List[IntArray]
132+
PY_RETURN_TYPE: list[IntArray]
133133
INCONV:
134134
IN: "%C% = iterable_of_vertex_index_iterable_to_igraph_vector_int_list_t(%I%)"
135135
OUT: "%C% = _VectorIntList.create(0)"
@@ -184,7 +184,7 @@ EDGE_INDICES:
184184

185185
EDGE_INDICES_LIST:
186186
PY_TYPE: Iterable[Iterable[EdgeLike]]
187-
PY_RETURN_TYPE: List[IntArray]
187+
PY_RETURN_TYPE: list[IntArray]
188188
INCONV:
189189
IN: "%C% = iterable_of_edge_index_iterable_to_igraph_vector_int_list_t(%I%)"
190190
OUT: "%C% = _VectorIntList.create(0)"

src/igraph_ctypes/_internal/attributes.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
py_object,
55
)
66
from dataclasses import dataclass, field
7-
from typing import Any, Callable, Dict, Optional
7+
from typing import Any, Callable, Optional
88

99
from .lib import igraph_error, igraph_vector_ptr_size
1010
from .refcount import incref, decref
@@ -34,7 +34,7 @@ class AttributeHandlerBase:
3434
_table: Optional[igraph_attribute_table_t] = None
3535
_table_ptr = None
3636

37-
def _get_attribute_handler_functions(self) -> Dict[str, Callable]:
37+
def _get_attribute_handler_functions(self) -> dict[str, Callable]:
3838
"""Returns an ``igraph_attribute_table_t`` instance that can be used
3939
to register this attribute handler in the core igraph library.
4040
"""
@@ -60,7 +60,7 @@ class AttributeStorage(ABC):
6060
"""
6161

6262
@abstractmethod
63-
def add_vertices(self, n: int) -> None:
63+
def add_vertices(self, graph, n: int) -> None:
6464
"""Notifies the attribute storage object that the given number of
6565
new vertices were added to the graph.
6666
"""
@@ -82,17 +82,17 @@ def copy(
8282

8383

8484
@dataclass(frozen=True)
85-
class DictAttributeStorage(AttributeStorage):
86-
"""Dictionary-based storage area for the graph, vertex and edge attributes
85+
class dictAttributeStorage(AttributeStorage):
86+
"""dictionary-based storage area for the graph, vertex and edge attributes
8787
of a graph.
8888
"""
8989

90-
graph_attributes: Dict[str, Any] = field(default_factory=dict)
91-
vertex_attributes: Dict[str, Any] = field(default_factory=dict)
92-
edge_attributes: Dict[str, Any] = field(default_factory=dict)
90+
graph_attributes: dict[str, Any] = field(default_factory=dict)
91+
vertex_attributes: dict[str, list] = field(default_factory=dict)
92+
edge_attributes: dict[str, Any] = field(default_factory=dict)
9393

9494
def add_vertices(self, graph, n: int) -> None:
95-
print("Added", n, "vertices")
95+
pass
9696

9797
def clear(self) -> None:
9898
"""Clears the storage area, removing all attributes from the
@@ -148,12 +148,12 @@ def _detach_storage_from_graph(graph) -> None:
148148

149149

150150
class AttributeHandler(AttributeHandlerBase):
151-
"""Attribute handler implementation that uses a DictAttributeStorage_
151+
"""Attribute handler implementation that uses a dictAttributeStorage_
152152
as its storage backend.
153153
"""
154154

155155
def init(self, graph, attr):
156-
_assign_storage_to_graph(graph, DictAttributeStorage())
156+
_assign_storage_to_graph(graph, dictAttributeStorage())
157157

158158
def destroy(self, graph) -> None:
159159
storage = _get_storage_from_graph(graph)

src/igraph_ctypes/_internal/conversion.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66

77
from ctypes import memmove, POINTER
8-
from typing import Any, Iterable, List, Optional, Sequence, TYPE_CHECKING
8+
from typing import Any, Iterable, Optional, Sequence, TYPE_CHECKING
99

1010
from .enums import MatrixStorage
1111
from .lib import (
@@ -659,17 +659,17 @@ def vertex_qtys_to_igraph_vector_t_view(
659659
################################################################################
660660

661661

662-
def igraph_vector_t_to_list(vector: _Vector) -> List[float]:
662+
def igraph_vector_t_to_list(vector: _Vector) -> list[float]:
663663
n = igraph_vector_size(vector)
664664
return [float(igraph_vector_e(vector, i)) for i in range(n)]
665665

666666

667-
def igraph_vector_bool_t_to_list(vector: _VectorBool) -> List[bool]:
667+
def igraph_vector_bool_t_to_list(vector: _VectorBool) -> list[bool]:
668668
n = igraph_vector_bool_size(vector)
669669
return [bool(igraph_vector_bool_e(vector, i)) for i in range(n)]
670670

671671

672-
def igraph_vector_int_t_to_list(vector: _VectorInt) -> List[int]:
672+
def igraph_vector_int_t_to_list(vector: _VectorInt) -> list[int]:
673673
n = igraph_vector_int_size(vector)
674674
return [int(igraph_vector_int_e(vector, i)) for i in range(n)]
675675

@@ -718,7 +718,7 @@ def igraph_vector_int_t_to_numpy_array(vector: _VectorInt) -> IntArray:
718718

719719
def igraph_vector_list_t_to_list_of_numpy_array(
720720
vector_list: _VectorList,
721-
) -> List[RealArray]:
721+
) -> list[RealArray]:
722722
n = igraph_vector_list_size(vector_list)
723723
vec = _Vector()
724724
result = []
@@ -736,7 +736,7 @@ def igraph_vector_list_t_to_list_of_numpy_array(
736736

737737
def igraph_vector_int_list_t_to_list_of_numpy_array(
738738
vector_list: _VectorIntList,
739-
) -> List[IntArray]:
739+
) -> list[IntArray]:
740740
n = igraph_vector_int_list_size(vector_list)
741741
vec = _VectorInt()
742742
result = []

0 commit comments

Comments
 (0)