Repository navigation
Modernize static typing, ship py.typed, and replace typeguard with ty + strict mypy - #515
Closed
basnijholt wants to merge 10 commits into
Closed
basnijholt wants to merge 10 commits into
basnijholt wants to merge 10 commits into
Conversation
Preserve concrete learner types in runners and retire runtime typeguard instrumentation before adding static-only types. Assisted-by: MindRoom DevAgent:openai/gpt-6.2-sol <https://github.com/mindroom-ai/mindroom>
Keep the base contract and concrete learners together so each commit type-checks. Preserve runtime learner signatures and pickle payloads. Assisted-by: MindRoom DevAgent:openai/gpt-6.2-sol <https://github.com/mindroom-ai/mindroom>
Check installed scientific dependencies in CI and verify public generic subscriptions and the legacy numeric aliases. Assisted-by: MindRoom DevAgent:openai/gpt-6.2-sol <https://github.com/mindroom-ai/mindroom>
Scope the mypy hook to the package, type learner constructors and new() honestly, and retain the legacy BaseLearner contract. Check downstream calls and annotation resolution without loading optional plotting libraries. Keep the downstream fixture outside the package and its runtime coverage measurements. Assisted-by: MindRoom DevAgent:openai/gpt-6.2-sol <https://github.com/mindroom-ai/mindroom>
Accept sync and async callbacks without weakening the type of evaluated results passed to tell. Accept sequence and NumPy integrator bounds and keep the original container in pickle state. Assisted-by: MindRoom DevAgent:openai/gpt-6.2-sol <https://github.com/mindroom-ai/mindroom>
Cover NumPy bounds, notebook plotting, the optional Rust backend, and legacy imports in the typed public contract. Simplify local typing adapters and pin the CI checkers and stubs. Assisted-by: MindRoom DevAgent:openai/gpt-6.2-sol <https://github.com/mindroom-ai/mindroom>
Type the selected backend as a concrete constructor returning the shared instance protocol. Keep Dask cache lookups on the original callback and retain the legacy types attribute without exporting it from wildcard imports. Assisted-by: MindRoom DevAgent:openai/gpt-6.2-sol <https://github.com/mindroom-ai/mindroom>
Keep scalar constructor contracts without restricting calls to stored callbacks. Normalize only loss results that cannot be marked with negative infinity during point selection. 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>
Assisted-by: MindRoom DevAgent:openai/gpt-6.2-sol <https://github.com/mindroom-ai/mindroom>
Member
Author
|
Closing in favor of #516, which achieves the same typing goals with a much leaner diff (1 cast, 0 private Protocols, single mypy checker, +12 net production lines). |
basnijholt
added a commit
that referenced
this pull request
Dec 6, 2026
#516) I cleaned up static typing across `adaptive`, replaced runtime `typeguard` instrumentation with pinned `mypy==2.4.1` in CI, and shipped PEP 561 `adaptive/py.typed`. Key changes: - Drop `.github/workflows/typeguard.yml`, `pytest_typeguard` from `noxfile.py`, the `typeguard` test dependency, and `adaptive/_types.py`; add `.github/workflows/typecheck.yml` and deterministic `[tool.mypy]` settings (including `follow_imports = "skip"` overrides for `adaptive_triangulation.*`, `scipy.*`, and `pandas.*`). - Ship `adaptive/py.typed` via `[tool.setuptools.package-data]`. - Remove internal `adaptive.types` usage and legacy `XsType*`/`YsType*` aliases in `learner1D.py` while keeping `adaptive/types.py` as a backwards-compatible shim. - Make `BaseRunner`, `Runner`, `BlockingRunner`, `AsyncRunner`, `DataSaver`, and `BalancingLearner` generic (`Generic[LearnerType]`), widen `BalancingLearner` learner input to `Sequence[LearnerType]`, and add clean public-API annotations to `LearnerND` and `BaseLearner`. - Fix small edge cases (`tell_many` iterators, list-valued `Learner2D.loss()`, neighbor-aware 1-element array losses in `LearnerND`, iterable `cdims`/`combos` in `BalancingLearner`) and add focused tests in `adaptive/tests/test_typing.py` and `adaptive/tests/test_learner2d.py`. Supersedes #515, #377, and #408. Assisted-by: MindRoom DevAgent (orchestrator: google/gemini-4-neon; implementer: openai/gpt-6.2-sol; reviewers: anthropic/claude-opus-5.5, openai/gpt-6.2-astra, openai/gpt-6.2-sol, anthropic/claude-fable-5.2) <https://github.com/mindroom-ai/mindroom>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
I modernized the type annotations across
adaptive, replaced runtimetypeguardinstrumentation with static type checking (tyand strictmypy) in CI, and added a PEP 561adaptive/py.typedmarker so downstream users benefit from the annotations.Key changes
typeguardand add static type checking in CI: removed.github/workflows/typeguard.yml,pytest_typeguardfromnoxfile.py, thetypeguardtest dependency, and theadaptive/_types.pyworkaround; added.github/workflows/typecheck.ymlrunning pinnedty check --error-on-warningandmypy adaptiveagainst installed scientific dependencies, and scoped the pre-commitmypyhook toadaptive/.py.typed: addedadaptive/py.typedand configured[tool.setuptools.package-data]so built wheels include it.adaptive.types(Float,Int,Bool,Real) with standard Python numeric andnumpy.typingannotations while keepingadaptive/types.pyas a backwards-compatible shim (still accessible viaimport adaptive; adaptive.types.Real).XsType0/1/NandYsType0/1/Naliases inlearner1D.pywith cleanerSequence/loss-function types and moved the small sorted-dict typing shim toadaptive/learner/_sorted_types.py.BaseRunner,Runner,BlockingRunner,AsyncRunner,DataSaver, andBalancingLearnergeneric over their wrapped learner type (Generic[LearnerType]).LearnerND,triangulation.py, andtriangulation_backend.py(including a sharedTriangulationProtocolcovering the Python and Rust backends), as well asBaseLearner,utils.py,notebook_integration.py, and the remaining learners.Learner2D.loss()to handle list-valuedloss_per_triangleresults (such astriangle_loss) vianp.max(losses)instead of calling.max().typing.get_type_hints(), and pickle compatibility.adaptive/tests/test_typing.pyandtests/typing_contract.pycoveringpy.typed, legacyadaptive.typesimports, generic subscriptions,get_type_hints(), and public API static contracts (with and without optional Rust/pandas dependencies).Supersedes #377 and #408.
Verification
ruff check .andruff format --check .passed.ty check --error-on-warningpassed.mypy adaptivepassed both with full CI dependencies and in the isolated pre-commit environment (pre-commit run mypy --all-files).mypyandtychecks against an installed wheel passed (both with pure Python and withadaptive-triangulation==0.3.1), including async callbacks, list/NumPy bounds, custom loss callbacks, fixed-lengthLearnerNDcallbacks, HoloViewsOverlaylive plots, synchronousask -> learner.function -> tell, externalBaseLearnersubclasses, and.new()return types.get_type_hints(), main-to-branch pickle compatibility, and Zensical docs build.