-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_v.py
More file actions
78 lines (59 loc) · 1.89 KB
/
error_v.py
File metadata and controls
78 lines (59 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
Python equivalent of the Fortran `ErrorV` class [TODO: x-refs]
At the moment, all written by hand.
We will auto-generate this in future.
"""
from __future__ import annotations
from attrs import define
from example_fgen_basic.pyfgen_runtime.exceptions import CompiledExtensionNotFoundError
try:
from example_fgen_basic._lib import ( # type: ignore
m_error_v_w,
)
except (ModuleNotFoundError, ImportError) as exc: # pragma: no cover
raise CompiledExtensionNotFoundError("example_fgen_basic._lib.m_error_v_w") from exc
NO_ERROR_CODE = 0
"""Code that indicates no error"""
@define
class ErrorV:
"""
Error value
"""
code: int = 1
"""Error code"""
message: str = ""
"""Error message"""
@classmethod
def from_instance_index(cls, instance_index: int) -> ErrorV:
"""
Initialise from an instance index received from Fortran
Parameters
----------
instance_index
Instance index received from Fortran
Returns
-------
:
Initialised index
"""
# Different wrapping strategies are needed
# Integer is very simple
code = m_error_v_w.get_code(instance_index)
# String requires decode
message = m_error_v_w.get_message(instance_index).decode()
res = cls(code=code, message=message)
return res
def build_fortran_instance(self) -> int:
"""
Build an instance equivalent to `self` on the Fortran side
Intended for use mainly by wrapping functions.
Most users should not need to use this method directly.
Returns
-------
:
Instance index of the object which has been created on the Fortran side
"""
instance_index: int = m_error_v_w.build_instance(
code=self.code, message=self.message
)
return instance_index