Add type checking via mypy#252
Open
samaloney wants to merge 6 commits into
Open
Conversation
* Add mypy config * Add mypy to pre-commit * Update code to pass mypy
samaloney
commented
Jul 2, 2026
Comment on lines
+256
to
+259
| dat = self._read_dat(file) | ||
| if isinstance(dat, list): | ||
| return dat | ||
| return [dat] |
Member
Author
There was a problem hiding this comment.
This was a potential bug found via type checking
samaloney
commented
Jul 2, 2026
| The background subtracted from the data. | ||
| """ | ||
| return self.meta.bg | ||
| return self.meta["background"] |
Member
Author
There was a problem hiding this comment.
This was a real bug found because of type checking
samaloney
marked this pull request as ready for review
July 2, 2026 19:16
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces static type checking to the radiospectra codebase by configuring mypy/pyright and updating core modules (spectrogram factory/base, plotting mixins, and several data-source clients) with type hints and small refactors to satisfy strict typing.
Changes:
- Add mypy/pyright configuration (strict mode) and update CI + pre-commit to run type checking.
- Annotate/refactor spectrogram factory/base, source classes, and net clients to pass type checking.
- Adjust plotting mixins/tests to match updated typing and interfaces.
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| radiospectra/version.py | Export control via __all__ for version symbol. |
| radiospectra/utils.py | Add numpy typing and annotate subband_to_freq. |
| radiospectra/spectrogram/tests/test_spectrogrambase.py | Update tests for the revised plotim() signature. |
| radiospectra/spectrogram/spectrogrambase.py | Add typing to GenericSpectrogram, registry, and metadata accessors. |
| radiospectra/spectrogram/spectrogram_factory.py | Add typing helpers/refactors and improve CDF parsing type-safety. |
| radiospectra/spectrogram/sources/waves.py | Add type hints and adjust metadata access patterns. |
| radiospectra/spectrogram/sources/tests/test_ilofar357.py | Update assertions to match changed mode return type. |
| radiospectra/spectrogram/sources/swaves.py | Add type hints for init/dispatch. |
| radiospectra/spectrogram/sources/rstn.py | Add type hints for dispatch. |
| radiospectra/spectrogram/sources/rpw.py | Add type hints for dispatch. |
| radiospectra/spectrogram/sources/psp_rfs.py | Add type hints and casts for CDF metadata fields. |
| radiospectra/spectrogram/sources/nda.py | Add typing and tighten return types for properties/dispatch. |
| radiospectra/spectrogram/sources/ilofar357.py | Add typing and change mode/polarisation property return types. |
| radiospectra/spectrogram/sources/eovsa.py | Add typing for init/dispatch and metadata access. |
| radiospectra/spectrogram/sources/callisto.py | Add typing for init/dispatch and observatory location property. |
| radiospectra/spectrogram/sources/init.py | Remove Spectrogram import side-effect from sources package init. |
| radiospectra/net/sources/wind.py | Add typing/casts and silence private API typing noise. |
| radiospectra/net/sources/rstn.py | Add typing/casts and minor mapping refactor. |
| radiospectra/net/sources/psp.py | Add typing/casts and receiver list handling. |
| radiospectra/net/sources/nda.py | Add typing/casts and refactor end-time extraction. |
| radiospectra/net/sources/learmonth.py | Add typing/casts for post_search_hook. |
| radiospectra/net/sources/ilofar.py | Add typing/casts and small refactors around query filtering. |
| radiospectra/net/sources/eovsa.py | Silence type checkers for an untyped/legacy client module. |
| radiospectra/net/sources/ecallisto.py | Add typing/casts and refine hook signatures. |
| radiospectra/net/attrs.py | Add type-ignore markers for SimpleAttr subclasses. |
| radiospectra/mixins.py | Add typing to plotting mixins and adjust plotim() signature/behavior. |
| radiospectra/_dev/scm_version.py | Annotate version as str for type checking. |
| pyproject.toml | Add mypy/pyright strict configuration and ignore patterns. |
| changelog/252.feature.rst | Add changelog entry for type checking integration. |
| .ruff.toml | Bump Ruff target version to Python 3.12. |
| .pre-commit-config.yaml | Add a mypy pre-commit hook with typing dependencies. |
| .github/workflows/ci.yml | Add a dedicated mypy job and wire it into the CI dependency chain. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+291
to
295
| dat = self._read_dat(file) | ||
| if isinstance(dat, list): | ||
| return dat | ||
| return [dat] | ||
| return self._read_dat(file) |
Comment on lines
+143
to
147
| def plotim(self: _SpectrogramLike, axes: Axes | None = None, **kwargs: Any) -> NonUniformImage: | ||
|
|
||
| if axes is None: | ||
| fig, axes = plt.subplots() | ||
| _, axes = plt.subplots() | ||
|
|
| - name: Set up Python | ||
| uses: actions/setup-python@v6 # zizmor: ignore[unpinned-uses] | ||
| with: | ||
| python-version: "3.13" |
Comment on lines
18
to
+20
| @property | ||
| def mode(self): | ||
| return self.meta.get("mode") | ||
| def mode(self) -> str: | ||
| return str(self.meta.get("mode")) |
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.
PR Description
Investigating #250 turns out wasn't as bad as I had imagined and caught two bugs
AI Assistance Disclosure
AI tools were used for: