Skip to content

Clean up static typing, ship py.typed, and replace typeguard with mypy - #516

Merged
basnijholt merged 8 commits into
mainfrom
lean-typing
Dec 6, 2026
Merged

basnijholt merged 8 commits into
mainfrom
lean-typing

Conversation

@basnijholt

@basnijholt basnijholt commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Summary

I simplified the type annotations across adaptive, replaced runtime typeguard instrumentation with a single pragmatic mypy check in CI, and added a PEP 561 adaptive/py.typed marker so downstream users benefit from the annotations.

Key changes

  • Drop typeguard and add mypy in CI: removed .github/workflows/typeguard.yml, pytest_typeguard from noxfile.py, the typeguard test dependency, and the adaptive/_types.py workaround; added .github/workflows/typecheck.yml running pinned mypy (check_untyped_defs, warn_unused_ignores, warn_redundant_casts, no_implicit_optional) and scoped the pre-commit mypy hook to adaptive/.
  • Ship PEP 561 py.typed: added adaptive/py.typed and configured [tool.setuptools.package-data] so built wheels include it.
  • Simplify annotations and preserve concrete learner types:
    • Removed internal uses of adaptive.types (Float, Int, Bool, Real) in favor of plain Python numeric and numpy types while keeping adaptive/types.py as a backwards-compatible shim (still accessible via import adaptive; adaptive.types.Real, without adding types to __all__).
    • Removed the brittle XsType0/1/N and YsType0/1/N aliases from learner1D.py (net shorter than main).
    • Made BaseRunner, Runner, BlockingRunner, AsyncRunner, DataSaver, and BalancingLearner generic (Generic[LearnerType]) so runner.learner and wrapped learners preserve their concrete type.
    • Added clean public-API annotations to LearnerND and BaseLearner with zero private Protocol classes, no added cast() calls, and # type: ignore cut roughly in half (78 -> 30).
    • Fixed Learner2D.loss() to handle list-valued loss_per_triangle results (such as triangle_loss) via float(np.max(losses)).
  • Add focused typing tests: added adaptive/tests/test_typing.py and a Learner2D list-loss test in adaptive/tests/test_learner2d.py.

Supersedes #515, #377, and #408.

Verification

  • ruff check . and ruff format --check . passed.
  • mypy adaptive passed both in the CI adaptive[test] environment and via pre-commit run mypy --all-files.
  • Downstream mypy and ty checks against a built wheel passed across all seven learners, generic wrappers, async callbacks, list/NumPy bounds, custom losses, and external BaseLearner subclasses.
  • Full pytest suites passed on Python 3.11 ([test,other]) and Python 3.13 ([test,other,rust]), plus wheel py.typed packaging and get_type_hints() compatibility checks.

Accept iterator batches, NumPy scalar observations, ndarray simplex losses, and typed balancing callbacks. Describe npoints as read-only for type checking without imposing a runtime property.

Assisted-by: MindRoom DevAgent:openai/gpt-6.2-sol <https://github.com/mindroom-ai/mindroom>
Assisted-by: MindRoom DevAgent:openai/gpt-6.2-sol <https://github.com/mindroom-ai/mindroom>
@basnijholt
basnijholt merged commit ca7a710 into main Dec 6, 2026
18 checks passed
@basnijholt
basnijholt deleted the lean-typing branch December 6, 2026 08:11
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