Skip to content

Commit 740c65d

Browse files
committed
feat: replaced create_boxed() with metaclasses, better for mypy
1 parent 6bcbe12 commit 740c65d

File tree

12 files changed

+356
-334
lines changed

12 files changed

+356
-334
lines changed

pyproject.toml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ name = "igraph_ctypes"
33
version = "0.0.0.post58.dev0+4ca9643"
44
description = ""
55
authors = ["Tamas Nepusz <[email protected]>"]
6-
packages = [
7-
{ include = "igraph_ctypes", from = "src" }
8-
]
6+
packages = [{ include = "igraph_ctypes", from = "src" }]
97

108
[tool.poetry.dependencies]
119
python = "^3.10"
1210
numpy = "^1.23.3"
13-
pycapi = "^0.82.1"
11+
pycapi = ">=0.82.1"
1412

1513
[tool.poetry.group.dev.dependencies]
1614
pytest = "^7.2.1"
@@ -25,6 +23,10 @@ enable = true
2523
[tool.poetry-dynamic-versioning.substitution]
2624
files = ["src/igraph_ctypes/_version.py"]
2725

26+
[[tool.mypy.overrides]]
27+
module = "igraph_ctypes._internal.wrappers"
28+
ignore_missing_imports = true
29+
2830
[tool.pytest.ini_options]
2931
addopts = "--cov-config=.coveragerc"
3032

@@ -42,18 +44,22 @@ select = ["B", "C", "E", "F", "W"]
4244
legacy_tox_ini = """
4345
[tox]
4446
min_version = 4.0
45-
env_list = py311, py310
47+
env_list = py311, py310, type
4648
4749
[gh-actions]
4850
python =
4951
3.10: py310
50-
3.11: py311
52+
3.11: py311, type
5153
5254
[testenv]
5355
deps =
5456
pytest
5557
pytest-cov
5658
commands = pytest tests
59+
60+
[testenv:type]
61+
deps = mypy
62+
commands = mypy src
5763
"""
5864

5965
[build-system]

src/codegen/internal_functions.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from ctypes import c_char_p, c_int
34
from typing import Any, Iterable, List, Optional, Tuple, TYPE_CHECKING
45

56
from .conversion import * # noqa

src/codegen/internal_lib.py.in

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
# type: ignore
2-
#
3-
# Type annotations are ignored in this file because pylance is not smart enough
4-
# to figure out that `restypes` and `argtypes` are valid for a function imported
5-
# from a library
6-
71
# fmt: off
82

93
from ctypes import cdll, c_char_p, c_double, c_int, c_void_p, POINTER
104
from ctypes.util import find_library
5+
from typing import Any
116

127
from .attributes import (
138
igraph_attribute_combination_t,
@@ -66,7 +61,7 @@ def _load_igraph_c_library():
6661
return lib
6762

6863

69-
_lib = _load_igraph_c_library()
64+
_lib: Any = _load_igraph_c_library()
7065

7166
# Vector type
7267

src/igraph_ctypes/_internal/attributes.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
POINTER,
99
Structure,
1010
)
11-
from dataclasses import dataclass, field, replace
11+
from dataclasses import dataclass, field
1212
from typing import Any, Callable, Dict, Optional
1313

14-
from .refcount import incref, decref, refcount
14+
from .refcount import incref, decref
1515
from .types import (
1616
igraph_bool_t,
1717
igraph_error_t,
@@ -26,7 +26,7 @@
2626
igraph_vector_t,
2727
igraph_vs_t,
2828
)
29-
from .utils import protect
29+
from .utils import nop, protect
3030

3131
__all__ = ("AttributeHandlerBase", "DictAttributeHandler")
3232

@@ -176,9 +176,7 @@ def _get_attribute_handler_functions(self) -> Dict[str, Callable]:
176176
to register this attribute handler in the core igraph library.
177177
"""
178178
return {
179-
key: igraph_attribute_table_t.TYPES[key](
180-
protect(getattr(self, key, self._nop))
181-
)
179+
key: igraph_attribute_table_t.TYPES[key](protect(getattr(self, key, nop)))
182180
for key in igraph_attribute_table_t.TYPES.keys()
183181
}
184182

@@ -191,10 +189,6 @@ def _as_parameter_(self):
191189
self._table_ptr = pointer(self._table)
192190
return self._table_ptr
193191

194-
@staticmethod
195-
def _nop():
196-
pass
197-
198192

199193
@dataclass(frozen=True)
200194
class _DictAttributeStorage:

0 commit comments

Comments
 (0)