Skip to content

Commit 00a53ed

Browse files
authored
Merge pull request #48 from linuxrider/type-checker
Type checker
2 parents 64669d8 + 422682d commit 00a53ed

8 files changed

Lines changed: 12697 additions & 11022 deletions

File tree

‎.github/workflows/doc.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ jobs:
1414
- name: checkout
1515
uses: actions/checkout@v6
1616
with: { submodules: recursive }
17-
- uses: prefix-dev/setup-pixi@v0.9.4
18-
with: { pixi-version: v0.63.2 }
17+
- uses: prefix-dev/setup-pixi@v0.9.6
18+
with: { pixi-version: v0.70.2 }
1919
- name: build documentation
2020
run: |
2121
pixi run doc

‎.github/workflows/lint.yml‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ jobs:
1414
- name: checkout
1515
uses: actions/checkout@v6
1616
with: { submodules: recursive }
17-
- uses: prefix-dev/setup-pixi@v0.9.4
18-
with: { pixi-version: v0.63.2 }
17+
- uses: prefix-dev/setup-pixi@v0.9.6
18+
with: { pixi-version: v0.70.2 }
1919
- name: pylint
2020
run: pixi run pylint
2121
- name: black
2222
run: pixi run black --diff --check
2323
- name: isort
24-
run: pixi run isort -- --check --diff
24+
run: pixi run isort -- --diff
25+
- name: ty
26+
run: pixi run ty

‎.github/workflows/test.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v6
1919
with: { submodules: recursive }
20-
- uses: prefix-dev/setup-pixi@v0.9.4
21-
with: { pixi-version: v0.63.2 }
20+
- uses: prefix-dev/setup-pixi@v0.9.6
21+
with: { pixi-version: v0.70.2 }
2222
- name: doctest
2323
shell: pixi run bash -e {0}
2424
run: pixi run -e ${{ matrix.environment }} doctest

‎ec_tools/helper.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66

77

8-
def find_x0_values(x, y, mode="all"):
8+
def find_x0_values(x: np.ndarray, y: np.ndarray, mode: str = "all") -> np.ndarray:
99
"""Takes x and y as numpy arrays and returns the ordered zero points by assuming linear behavior between
1010
the points.
1111
The mode determines if all or either positive or negative zero points should be returned.
@@ -55,7 +55,7 @@ def find_x0_values(x, y, mode="all"):
5555
return np.sort(np.concatenate([x[exact_crossings[1::2]], delta_x + x[non_exact_crossings]]))
5656

5757

58-
def determine_scan_rate(t, x):
58+
def determine_scan_rate(t: np.ndarray, x: np.ndarray) -> np.floating:
5959
"""Return scan rate of given t and x arrays.
6060
6161
TEST:
@@ -69,7 +69,7 @@ def determine_scan_rate(t, x):
6969
return np.abs(np.diff(x) / np.diff(t)).mean()
7070

7171

72-
def detect_step(t, x):
72+
def detect_step(t: np.ndarray, x: np.ndarray) -> np.intp:
7373
"""Returns the index of the step in given t and x arrays.
7474
Index is the where the changed value of t located.
7575
TEST:

‎ec_tools/py.typed‎

Whitespace-only changes.

‎ec_tools/semi_integration.py‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,14 @@
154154
from transonic import jit
155155

156156

157-
def semi_integration(y, x, v=-0.5, alg="frlt", transonic_backend="pythran", d_tol=1e-5):
157+
def semi_integration(
158+
y: np.ndarray,
159+
x: np.ndarray,
160+
v: float = -0.5,
161+
alg: str = "frlt",
162+
transonic_backend: str = "pythran",
163+
d_tol: float = 1e-5,
164+
) -> np.ndarray:
158165
r"""
159166
A generalized call is implemented, in which the user can define with ``v`` the operation i.e. semi integration
160167
(``v`` :math:`=-0.5`) or semi differentiation (``v`` :math:`=0.5`) for a predefined dataset (``y`` and ``t``).
@@ -271,8 +278,10 @@ def riemann_pythran(y, delta_x, v):
271278

272279
return riemann_pythran(y, delta_x, v)
273280

281+
raise AssertionError(f"unhandled alg/backend combination: {alg!r}/{transonic_backend!r}")
274282

275-
def gruenwald(y, delta_x, v=-0.5):
283+
284+
def gruenwald(y: np.ndarray, delta_x: float, v: float = -0.5) -> np.ndarray:
276285
"""
277286
Gruenwald Algorithm
278287
^^^^^^^^^^^^^^^^^^^
@@ -331,7 +340,7 @@ def gruenwald(y, delta_x, v=-0.5):
331340
return g_1
332341

333342

334-
def riemann(y, delta_x, v=-0.5):
343+
def riemann(y: np.ndarray, delta_x: float, v: float = -0.5) -> np.ndarray:
335344
"""
336345
337346
Riemann Algorithm
@@ -399,7 +408,7 @@ def riemann(y, delta_x, v=-0.5):
399408
return r_1
400409

401410

402-
def fast_riemann(y, delta_x=1, q=-0.5, c1=8, c2=2):
411+
def fast_riemann(y: np.ndarray, delta_x: float = 1, q: float = -0.5, c1: int = 8, c2: int = 2) -> np.ndarray:
403412
r"""
404413
405414
Fast Riemann Algorithm

‎pixi.lock‎

Lines changed: 12661 additions & 11006 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pyproject.toml‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ pythran = ["pythran"]
1919
[tool.setuptools]
2020
packages = ["ec_tools",]
2121

22+
[tool.setuptools.package-data]
23+
ec_tools = ["py.typed"]
24+
2225
[tool.pixi.workspace]
2326
channels = ["conda-forge"]
2427
platforms = ["linux-64", "linux-aarch64", "osx-64", "osx-arm64", "win-64"]
@@ -78,13 +81,15 @@ scipy = "*"
7881
benchmark = "TODO"
7982

8083
[tool.pixi.feature.lint.dependencies]
81-
ruff = ">=0.15.0,<0.16"
84+
ruff = ">=0.15.17,<0.16"
85+
ty = ">=0.0.49,<0.0.50"
8286

8387
[tool.pixi.feature.lint.tasks]
8488
pylint = "ruff check ec_tools"
8589
black = "ruff format ec_tools"
8690
isort = "ruff check --select I ec_tools"
87-
lint = { depends-on = ["pylint", "black", "isort"] }
91+
ty = "ty check --python $CONDA_PREFIX ec_tools"
92+
lint = { depends-on = ["pylint", "black", "isort", "ty"] }
8893

8994
[tool.pixi.feature.doc.dependencies]
9095
jupytext = "*"
@@ -115,3 +120,7 @@ lint.ignore = [
115120
]
116121
lint.fixable = ["E", "F", "W", "B"]
117122
line-length = 115
123+
124+
[tool.ty.environment]
125+
# Check against the oldest supported interpreter (see requires-python).
126+
python-version = "3.10"

0 commit comments

Comments
 (0)