Skip to content

Commit 3c2a6a4

Browse files
committed
Mypy
1 parent 999f35f commit 3c2a6a4

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/example_fgen_basic/get_square_root.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
) from exc
1919

2020
try:
21-
from example_fgen_basic._lib import m_result_dp_w # type: ignore
21+
from example_fgen_basic._lib import m_result_dp_w
2222
except (ModuleNotFoundError, ImportError) as exc: # pragma: no cover
2323
raise CompiledExtensionNotFoundError(
2424
"example_fgen_basic._lib.m_result_dp_w"
@@ -49,11 +49,14 @@ def get_square_root(inv: float) -> float:
4949
result_instance_index: int = m_get_square_root_w.get_square_root(inv)
5050
result = ResultDP.from_instance_index(result_instance_index)
5151

52-
if result.has_error:
52+
if result.error_v is not None:
5353
# TODO: be more specific
5454
raise FortranError(result.error_v.message)
5555
# raise LessThanZeroError(result.error_v.message)
5656

57+
if result.data_v is None:
58+
raise AssertionError
59+
5760
res = result.data_v
5861

5962
# TODO: think

src/example_fgen_basic/result/result_dp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ class ResultDP:
2828
# TODO: add validation that one of data_v and error_v is provided but not both
2929

3030
# data_v: np.Float64
31-
data_v: float
31+
data_v: float | None
3232
"""Data"""
3333

34-
error_v: ErrorV
34+
error_v: ErrorV | None
3535
"""Error"""
3636

3737
@classmethod
38-
def from_instance_index(cls, instance_index: int) -> ErrorV:
38+
def from_instance_index(cls, instance_index: int) -> ResultDP:
3939
"""
4040
Initialise from an instance index received from Fortran
4141
@@ -53,7 +53,7 @@ def from_instance_index(cls, instance_index: int) -> ErrorV:
5353

5454
# Integer is very simple
5555
if m_result_dp_w.data_v_is_set(instance_index):
56-
data_v: float = m_result_dp_w.get_data_v(instance_index)
56+
data_v: float | None = m_result_dp_w.get_data_v(instance_index)
5757
# data_v: np.Float64 = m_result_dp_w.get_data_v(instance_index)
5858

5959
else:

0 commit comments

Comments
 (0)