Repository navigation
ENH: Add type annotations to ICA() parameters - #14583
draarivpatel-ui wants to merge 1 commit into
Conversation
|
Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴 |
|
thanks for the contribution! As we work our way toward completing type-hints across the whole public API, we're taking the approach of doing one entire submodule at a time so that we can enable the type-checker to run on that submodule in our pre-commit hook (see Lines 522 to 530 in 387a0dd Are you willing to tackle type-hinting the whole |
Reference issue (if any)
Closes #13597.
What does this implement/fix?
Adds type annotations to the
ICA.__init__signature so that calls accepted at runtime and documented, such asICA(n_components=3, max_iter=1000), no longer produce false positives in static type checkers. Previously the parameters were unannotated, so checkers inferred each one from its default value (for examplemax_iterwas treated asstrand rejected integer values).Each annotation matches the documented parameter types in the class docstring:
n_components:int | float | Nonenoise_cov:Covariance | Nonerng:int | Generator | RandomState | Nonerandom_state:int | RandomState | Nonemethod:Literal["fastica", "infomax", "jamica", "picard"]fit_params:dict | Nonemax_iter:int | Literal["auto"]allow_ref_meg:boolverbose:bool | str | int | NoneThe internal-only
method="imported_eeglab"used byread_ica_eeglabstays out of the public annotation (it remains undocumented) and the call site carries aty: ignorecomment.Additional information
Verified locally with a fresh venv on this branch:
ruff checkandruff format --checkpass,codespell/rstcheckpass on the changelog fragment,pytest mne/tests/test_docstring_parameters.pypasses (18 tests includingtest_type_hints_match_docstrings),pytest mne/preprocessing/tests/test_ica.py::test_ica_max_iter_andtest_ica_rng_transitionpass, amypycheck of a user-side script exercising every parameter reports no issues, andtyreports one fewer diagnostic on the file than on main (no new ones introduced).AI assistance disclosure: this PR was prepared with AI assistance (Devin, SWE-2 Max). The tool inspected the issue and runtime validation, wrote the annotations and changelog fragment, ran the checks listed above, and drafted this description. I reviewed the diff and take responsibility for its contents.