Skip to content

Commit 7fe3e43

Browse files
committed
Fix more warnings enabled from Scientific Python guide
1 parent f092146 commit 7fe3e43

File tree

7 files changed

+16
-13
lines changed

7 files changed

+16
-13
lines changed

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ dev = [
5151
"clang-format~=14.0",
5252

5353
# Linting
54-
"ruff>=0.2",
54+
"ruff>=0.6",
5555
"mypy",
5656
"codespell",
5757
"check-manifest",
@@ -104,7 +104,6 @@ syntax = "numpy"
104104

105105

106106
[tool.ruff]
107-
src = ["src"]
108107
line-length = 120
109108
output-format = "full"
110109

@@ -185,10 +184,12 @@ show_missing = true
185184

186185

187186
[tool.mypy]
187+
strict = true
188188
plugins = ["numpy.typing.mypy_plugin"]
189189
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
190190
warn_return_any = true
191191
warn_unused_configs = true
192+
warn_unreachable = true
192193
pretty = true
193194
ignore_missing_imports = true # This could be made local for the tests
194195

src/charonload/_compat/hashlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def file_digest(fileobj: BinaryIO, digest: str | Callable[[], _Hash], /) -> _Has
1919
elif callable(digest):
2020
file_hasher = digest()
2121
else:
22-
msg = "Wrong type of digest: Should be either str or Callable."
22+
msg = "Wrong type of digest: Should be either str or Callable." # type: ignore[unreachable]
2323
raise TypeError(msg)
2424

2525
num_blocks = 1024

src/charonload/_finder.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
class JITCompileFinder(importlib.abc.MetaPathFinder):
4141
"""An import finder for executing the just-in-time (JIT) compilation."""
4242

43-
def find_spec(self: Self, fullname, path, target=None) -> None: # noqa: ANN001, ARG002
43+
def find_spec( # type: ignore[no-untyped-def]
44+
self: Self, fullname, path, target=None # noqa: ANN001, ARG002
45+
) -> None:
4446
"""
4547
Find the spec of the specified module.
4648
@@ -96,7 +98,7 @@ def find_spec(self: Self, fullname, path, target=None) -> None: # noqa: ANN001,
9698

9799
def _load(module_name: str, config: ResolvedConfig) -> None:
98100
if not isinstance(config, ResolvedConfig):
99-
msg = f"Invalid type of configuration: expected 'Config', but got '{config.__class__.__name__}'"
101+
msg = f"Invalid type of configuration: expected 'Config', but got '{config.__class__.__name__}'" # type: ignore[unreachable]
100102
raise TypeError(msg)
101103

102104
(config.full_build_directory / "charonload").mkdir(parents=True, exist_ok=True)
@@ -500,7 +502,7 @@ def add(self: Self, d: pathlib.Path) -> None:
500502
@staticmethod
501503
def _clear(directories: dict[pathlib.Path, Any]) -> None:
502504
for handler in directories.values():
503-
handler.close() # type: ignore[attr-defined]
505+
handler.close()
504506

505507

506508
_windows_dll_directories: dict[pathlib.Path, Any] = {}

src/charonload/_persistence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class _Serializer:
5353
decode: Callable[[str], Any]
5454

5555

56-
class _PersistentDict(collections.abc.MutableMapping):
56+
class _PersistentDict(collections.abc.MutableMapping[str, Any]):
5757
def __init__(self: Self) -> None:
5858
self._entries: dict[str, _TypedPersistentString] = {}
5959
self._serializers: dict[type, _Serializer] = {}
@@ -76,7 +76,7 @@ def __delitem__(self: Self, key: str) -> None:
7676
msg = "Deleting connections is not supported."
7777
raise AttributeError(msg)
7878

79-
def __iter__(self: Self) -> collections.abc.Iterator:
79+
def __iter__(self: Self) -> collections.abc.Iterator[str]:
8080
return iter(self._entries)
8181

8282
def __len__(self: Self) -> int:

src/charonload/cmake/torch/add_torch_library.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// Define some bindings ...
2727
}
2828
29-
3. The usage requirements for PyTorch will be added to ``<name>`` and, if necessary,
29+
3. The :doc:`usage requirements for PyTorch</src/pytorch_handling>` will be added to ``<name>`` and, if necessary,
3030
recursively to all of its dependencies:
3131
3232
- C++ standard

src/charonload/pybind11_stubgen/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def main() -> None:
4646
# Patch list of command line argument globally as this list cannot directly be passed to pybind11-stubgen
4747
sys.argv = [sys.argv[0], *original_args]
4848

49-
pybind11_stubgen.main()
49+
pybind11_stubgen.main() # type: ignore[no-untyped-call]
5050

5151

5252
if __name__ == "__main__": # pragma: no cover

tests/test_finder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_installed_project() -> None:
3939
assert config.full_stubs_directory not in config.full_project_directory.parents
4040

4141
t_input = torch.randint(0, 10, size=(3, 3, 3), dtype=torch.float, device="cpu")
42-
t_output = charonload_installed_project.two_times(t_input)
42+
t_output = charonload_installed_project.two_times(t_input) # type: ignore[attr-defined]
4343

4444
assert t_output.device == t_input.device
4545
assert t_output.shape == t_input.shape
@@ -399,7 +399,7 @@ def _torch_incremental_build(
399399
p.join()
400400
assert p.exitcode == 0
401401

402-
return float(result.value) # type: ignore[attr-defined]
402+
return float(result.value)
403403

404404

405405
def test_torch_incremental_build_cpp(shared_datadir: pathlib.Path, tmp_path: pathlib.Path) -> None:
@@ -1009,7 +1009,7 @@ def test_concurrent_process_fork_import(shared_datadir: pathlib.Path, tmp_path:
10091009

10101010
num = 5
10111011
jobs = [
1012-
multiprocessing.get_context("fork").Process(target=_concurrent_process_fork_import, args=(i,)) # type: ignore[attr-defined]
1012+
multiprocessing.get_context("fork").Process(target=_concurrent_process_fork_import, args=(i,))
10131013
for i in range(num)
10141014
]
10151015

0 commit comments

Comments
 (0)