Skip to content

Commit 801c945

Browse files
committed
Add typing module and TODOs
1 parent 52a6ec8 commit 801c945

7 files changed

Lines changed: 55 additions & 8 deletions

File tree

TODO.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- read through everything
2+
- check docstrings
3+
- check naming (if you want to propose a consistent naming convention, go for it)
4+
- consider adding `m_error_v_w.build_instances` too, might be headache to pass arrays of things up and down correctly
5+
- clean up
6+
- final review (including deleting this file)
7+
- merge
8+
- move onto a basic result type with a subclass specifically for integers (`ResultInt` or something)

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ if pyprojectwheelbuild_enabled
8282
'src/example_fgen_basic/get_wavelength.py',
8383
'src/example_fgen_basic/pyfgen_runtime/__init__.py',
8484
'src/example_fgen_basic/pyfgen_runtime/exceptions.py',
85+
'src/example_fgen_basic/typing.py',
8586
)
8687

8788
# The ancillary library,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ source = [
149149
]
150150
branch = true
151151
omit = [
152-
# TODO: check this file
152+
# TODO: test these files directly when splitting out pyfgen_runtime
153153
"*exceptions.py",
154154
"*runtime_helpers.py",
155155
]

src/example_fgen_basic/error_v/creation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
) from exc
2929

3030
if TYPE_CHECKING:
31-
# TODO: bring back in numpy type hints
32-
NP_ARRAY_OF_INT = None
31+
from example_fgen_basic.typing import NP_ARRAY_OF_INT
3332

3433

3534
def create_error(inv: int) -> ErrorV:

src/example_fgen_basic/error_v/error_v_manager.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
!>
33
!> Written by hand here.
44
!> Generation to be automated in future (including docstrings of some sort).
5-
!
6-
! TODO: make it possible to reallocate the number of instances
75
module m_error_v_manager
86

97
use m_error_v, only: ErrorV

src/example_fgen_basic/error_v/passing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
) from exc
3131

3232
if TYPE_CHECKING:
33-
# TODO: bring back in numpy type hints
34-
NP_ARRAY_OF_INT = None
35-
NP_ARRAY_OF_BOOL = None
33+
from example_fgen_basic.typing import NP_ARRAY_OF_BOOL, NP_ARRAY_OF_INT
3634

3735

3836
def pass_error(inv: ErrorV) -> bool:

src/example_fgen_basic/typing.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Type hints which are too annoying to remember
3+
"""
4+
5+
from __future__ import annotations
6+
7+
from typing import TYPE_CHECKING
8+
9+
if TYPE_CHECKING:
10+
from typing import Any, TypeAlias, Union
11+
12+
import numpy as np
13+
import numpy.typing as npt
14+
15+
NP_ARRAY_OF_INT: TypeAlias = npt.NDArray[np.integer]
16+
"""
17+
Type alias for an array of numpy int
18+
"""
19+
20+
NP_ARRAY_OF_FLOAT: TypeAlias = npt.NDArray[np.floating]
21+
"""
22+
Type alias for an array of numpy floats
23+
"""
24+
25+
NP_FLOAT_OR_INT: TypeAlias = Union[np.floating, np.integer]
26+
"""
27+
Type alias for a numpy float or int (not complex)
28+
"""
29+
30+
NP_ARRAY_OF_FLOAT_OR_INT: TypeAlias = npt.NDArray[NP_FLOAT_OR_INT]
31+
"""
32+
Type alias for an array of numpy float or int (not complex)
33+
"""
34+
35+
NP_ARRAY_OF_NUMBER: TypeAlias = npt.NDArray[np.number[Any]]
36+
"""
37+
Type alias for an array of numpy float or int (including complex)
38+
"""
39+
40+
NP_ARRAY_OF_BOOL: TypeAlias = npt.NDArray[np.bool]
41+
"""
42+
Type alias for an array of booleans
43+
"""

0 commit comments

Comments
 (0)