Skip to content

Typehint - #27

Merged
zhengp0 merged 3 commits into
0.0.xfrom
typehint
Jun 30, 2026
Merged

Typehint#27
zhengp0 merged 3 commits into
0.0.xfrom
typehint

Conversation

@zhengp0

@zhengp0 zhengp0 commented Jun 30, 2026

Copy link
Copy Markdown
Member

Summary

Add type hints to the public functions and methods in core.py and
utils.py, and fix option_to_list so the per-dimension *_list
options actually work as documented. Also modernize the CI workflow,
which is required because the new typing syntax needs Python >= 3.10.

Typing conventions used:

  • numpy.typing.NDArray for real arrays, numpy.typing.ArrayLike for
    the knot inputs that get normalized via np.array/np.asarray
    (the XSpline / NDXSpline constructors).
  • float | NDArray (simple unions, no @overload) for the
    scalar-or-array math functions, matching how the code branches on
    np.isscalar.

What changed

  • src/xspline/utils.py — annotated all functions (args + returns).
    Notable: order_to_index(shape) is tuple[int, ...] | NDArray
    (tuple in tests, ndarray in core.py); funcs is
    list[Callable[..., float | NDArray]]; outer_flatten(*args: NDArray).
  • src/xspline/utils.py (option_to_list)behavior fix.
    Previously any non-empty list was truthy and collapsed to all-True,
    so per-dimension lists were silently ignored. It now accepts a single
    bool, None, or a real list[bool] (length-checked), returning the
    list as-is. Signature: bool | list[bool] | None.
  • src/xspline/core.py — annotated the four bspline_* functions,
    the XSpline / NDXSpline methods, constructors (-> None), and the
    nested integration piece helpers in ifun. The *_list /
    *_extra_list params are typed bool | list[bool] | None to keep the
    scalar/None convenience while enabling real lists.
  • tests/test_utils.py — replaced the previously vacuous
    test_utils_option_to_list (its ~(a ^ b) assertion was always
    truthy) with assertions that actually check the values, plus new tests
    for the real-list path and the length-mismatch guard.
  • .github/workflows/python-build.yml — bumped the test Python to
    3.11 (the new X | Y / list[bool] syntax needs >= 3.10, which was
    the CI failure), and updated action versions:
    actions/checkout@v2 -> v4, actions/setup-python@v2 -> v5,
    pypa/gh-action-pypi-publish@master -> @release/v1.

@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@zhengp0
zhengp0 merged commit b9ce1d2 into 0.0.x Jun 30, 2026
1 of 2 checks passed
@zhengp0
zhengp0 deleted the typehint branch June 30, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant