gh-983: fix some typing ignores, sort fixtures, tidy typing - #1095
Conversation
There was a problem hiding this comment.
Pull request overview
This PR focuses on reducing/cleaning ty suppressions and tightening typing across the library and its test suite, while also applying small formatting/consistency updates (e.g., fixture typing and line wrapping). It also updates coverage configuration patterns to account for typing.-qualified typing constructs.
Changes:
- Replaced several
ty: ignore[...]return-type suppressions with explicittyping.cast(...)in core modules. - Updated typing imports to be more selective/consistent (favoring
import typing+typing.Protocol/typing.overloadpatterns). - Tidied tests/benchmarks: fixture parameter annotations (
type[...]) and consistent formatting/wrapping; updated coverage exclude regexes.
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/fixtures/helper_classes.py | Minor formatting tweak in helper fixture class generation. |
| tests/core/test_user.py | Formatting-only wrap for readability/consistency. |
| tests/core/test_shells.py | Formatting-only wraps for test function signatures. |
| tests/core/test_shapes.py | Formatting-only wraps for test function signatures. |
| tests/core/test_points.py | Correct fixture type annotations (type[...]) and signature formatting. |
| tests/core/test_observations.py | Formatting-only wraps for test function signatures. |
| tests/core/test_lensing.py | Removes a now-unnecessary ty: ignore after overload typing improvements. |
| tests/core/test_harmonics.py | Formatting-only wraps for test function signatures. |
| tests/core/test_galaxies.py | Formatting-only wraps for test function signatures. |
| tests/core/test_fields.py | Formatting-only wraps plus minor assertion formatting. |
| tests/core/test_arraytools.py | Formatting-only wraps for test function signatures. |
| tests/core/test_algorithm.py | Formatting-only wraps for test function signatures. |
| tests/core/grf/test_transformations.py | Formatting-only wraps for test function signatures. |
| tests/core/grf/test_solver.py | Formatting-only wraps for test function signatures. |
| tests/core/grf/test_core.py | Formatting-only wraps for test function signatures. |
| tests/benchmarks/test_shells.py | Fixes benchmark fixture parameter annotation to type[Compare]. |
| tests/benchmarks/test_points.py | Fixes benchmark fixture parameter annotations to type[...]. |
| tests/benchmarks/test_fields.py | Fixes benchmark fixture parameter annotations to type[...]. |
| pyproject.toml | Updates coverage exclusion regexes for typing.-qualified constructs. |
| glass/shells.py | Replaces invalid-return-type ignore with explicit casts; adds import typing. |
| glass/shapes.py | Casts ellipticity outputs to ComplexArray; adds import typing. |
| glass/points.py | Moves Any import under TYPE_CHECKING and removes an unnecessary local annotation. |
| glass/lensing.py | Switches to typing.overload and casts; adjusts overload defaults for the all-False case. |
| glass/grf/_core.py | Uses typing.Protocol instead of importing Protocol directly. |
| glass/galaxies.py | Formatting-only change (trailing comma / wrapping). |
| glass/fields.py | Replaces return-type ignore(s) with casts; adds import typing; small formatting wrap. |
| glass/ext/init.py | Removes an unnecessary ty: ignore by simplifying return expression. |
| glass/cosmology.py | Uses typing.Protocol instead of importing Protocol directly. |
| glass/arraytools.py | Replaces an assignment ignore with an explicit cast around xpx.union1d. |
| glass/_types.py | Uses typing.ParamSpec/typing.TypeVar (via import typing) under TYPE_CHECKING. |
| glass/_array_api_utils.py | Moves Any import under TYPE_CHECKING to reduce runtime typing imports. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
connoraird
left a comment
There was a problem hiding this comment.
It's a shame we have to call typing stuff in the actual function bodies but I guess it's worth it.
Yeah, it's weird, haven't done it before. But this feels like a better (temporary) fix rather than just suppressing all errors with a |
Description
Reattempt at #1094. Tidying up some
ty: ignorestatements. Sorting fixtures alphabetically and fix the missingtype[]typing.. Also be more selective onfrom typing import <x>.Closes: #983, #1071
Checks