Skip to content

Improve type checks#14036

Open
larsoner wants to merge 20 commits into
mne-tools:mainfrom
larsoner:types
Open

Improve type checks#14036
larsoner wants to merge 20 commits into
mne-tools:mainfrom
larsoner:types

Conversation

@larsoner

@larsoner larsoner commented Jul 8, 2026

Copy link
Copy Markdown
Member
  1. Move from mypy to ty, including as pre-commit as ty is fast enough 🚀
  2. Add a consistency check for documented types (NumpyDoc) and our types (this check could eventually move to docstub but let's use it here for a bit)
  3. Stricter enforcement (mypy missed some stuff) and checking in epochs.py, evoked.py, and mne/io
  4. Correctly type the io.read_raw_*, but keep their docs/ / website aliases pointing to publicly documented objects
  5. Most typing changes were of the form 1) dict[str, Any], 2) assert x is not None for when x is self._data etc. (places where we know it is by code structure), plus using __getattr__ and __setattr__ to get *Bunch classes to play nicely
  6. Some simplification of ctf/res4.py because type checkers have trouble with NumPy structured arrays
  7. Various minor fixes caught by the tests + checker, like instance of RawEDF where we should have had instance of RawBDF

Used Claude Opus 4.8 to help me with the drudgery of assert x is not None etc., but I also made a lot of changes myself, and understand + vouch for all code.

larsoner added 3 commits July 8, 2026 17:16
* upstream/main:
  Fix transition bandwidth reported in 'filter too short' error (mne-tools#11406) (mne-tools#14005)
@larsoner

larsoner commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

Okay too many packages needed for type checking made pre-commit.ci unhappy, so here I move to prek + prek-action in autofix.yml instead. pre-commit.ci will be red here, but once we're happy with this PR we can merge it and disable pre-commit.ci and use prek. (prek uses the preexisting .pre-commit-config.yml and is a nice, faster version of it.) We could also consider other toolsk, but prek is the least invasive to existing dev workflows (people can continue to equvialently continue using pre-commit locally if they want!)

@larsoner

larsoner commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

A tiny bit of stuff here would get simpler if we dropped 3.10 support. 3.11 is actually almost out of SPEC0 so I don't mind dropping 3.10 now. But not too painful to keep it. It's EOL in October.

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