Skip to content

Use ty instead of mypy#636

Draft
marcpaterno wants to merge 12 commits into
masterfrom
use-ty-instead-of-mypy
Draft

Use ty instead of mypy#636
marcpaterno wants to merge 12 commits into
masterfrom
use-ty-instead-of-mypy

Conversation

@marcpaterno
Copy link
Copy Markdown
Collaborator

Description

This PR changes from using mypy to using ty for type checking.
ty is much faster than mypy. 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.

  • Refactoring

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.

  • I have run bash pre-commit-check and fixed any issues
  • I have added tests that prove my fix is effective or that my feature works
  • I have made corresponding changes to the documentation
  • I have 100% test coverage for my changes (please check this after the CI system has verified the coverage)

marcpaterno added 12 commits May 6, 2026 17:59
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.
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