Use ty instead of mypy#636
Draft
marcpaterno wants to merge 12 commits into
Draft
Conversation
Update project tooling from mypy to ty. Regenerate conda lock files and update CI, docs, and config to reflect the new type checker.
Rename parameters previously using the `_` or `_foo` convention to their real names and add `del param` statements to satisfy ty's unused-parameter checks. Add missing type annotations and return types where they were part of the same signatures.
Replace direct access to sacc.standard_types attributes with dynamically retrieved constants using getattr and fallback values. This improves compatibility and gracefully handles cases where these attributes may not be available in the SACC library.
sacc.BaseTracer does not declare lower/upper/center attributes; they exist only on specific subclasses. Define _BoundedTracer and _RadiusTracer protocols and use cast() to make the attribute access type-safe.
clmm.Cosmology and clmm.Modeling are dynamically set to None until a backend is loaded. Add a runtime None guard that raises RuntimeError if the backend is unavailable, and wrap both constructor calls with cast(Any, ...) to satisfy the type checker while preserving runtime behavior.
CCLCalculatorArgs supports iteration via .items() but is not necessarily a dict, so dict.update() is not type-safe here.
> The return type of dict.values() is a view, not a list. Wrapping in list() satisfies the type annotation without changing behavior.
UserList.__setitem__ accepts both int and slice keys. Handle both cases with proper Updatable type validation. Add tests for valid slice assignment, non-iterable rejection, and non-Updatable item rejection.
…ction Extract the duplicated recursive loop into recurse_children(). Use cast(UpdatableProtocol, ...) and early return for clarity.
Move TestModel to module scope, eliminating duplicate definitions across multiple test functions. Remove tests that accessed Pydantic internal schema details via __get_pydantic_core_schema__, replacing that coverage with higher-level tests that use model_validate. Switch direct construction with untyped args to model_validate for validation tests. Strengthen the serialization assertion from a substring check to an equality check. Add cast to satisfy the type checker.
Wrap all get_model() calls in the Cobaya connector tests with cast(InputDict, ...) to satisfy the `ty`type checker, which requires the argument to be typed as InputDict rather than a plain dict. Add the necessary imports: cast from typing and InputDict from cobaya.typing.
The return type of cobaya's logposterior() is not statically typed to expose .logpost, causing type checker errors. Add the LogPosterior import and cast each logposterior() call site to that type.
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.
Description
This PR changes from using
mypyto usingtyfor type checking.tyis much faster thanmypy. But they differ in the details of what typing issues each catches.Type of change
Please delete the bullet items below that do not apply to this pull request.
Checklist:
The following checklist will make sure that you are following the code style and
guidelines of the project as described in the
contributing page.
bash pre-commit-checkand fixed any issues