Skip to content

Add type checking via mypy#252

Open
samaloney wants to merge 6 commits into
sunpy:mainfrom
samaloney:feature-typing
Open

Add type checking via mypy#252
samaloney wants to merge 6 commits into
sunpy:mainfrom
samaloney:feature-typing

Conversation

@samaloney

@samaloney samaloney commented Jul 2, 2026

Copy link
Copy Markdown
Member

PR Description

Investigating #250 turns out wasn't as bad as I had imagined and caught two bugs

  • Add mypy config
  • Add mypy to pre-commit
  • Update code to pass mypy

AI Assistance Disclosure

AI tools were used for:

  • [ ] Code generation (e.g., when writing an implementation or fixing a bug)
  • [ ] Test/benchmark generation
  • [ ] Documentation (including examples)
  • [ ] Research and understanding
  • [x ] No AI tools were used

Regardless of AI use, the human contributor remains fully responsible for correctness, design choices, licensing compatibility, and long-term maintainability.

* Add mypy config
* Add mypy to pre-commit
* Update code to pass mypy
Comment on lines +256 to +259
dat = self._read_dat(file)
if isinstance(dat, list):
return dat
return [dat]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a potential bug found via type checking

The background subtracted from the data.
"""
return self.meta.bg
return self.meta["background"]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a real bug found because of type checking

@samaloney
samaloney marked this pull request as ready for review July 2, 2026 19:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread radiospectra/mixins.py
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()

Comment thread .github/workflows/ci.yml
- 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"))
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.

2 participants