Add mypy type checking support and fix all type errors - #79
MLopez-Ibanez with Copilot wants to merge 8 commits into
Conversation
…tils.py Co-authored-by: MLopez-Ibanez <2620021+MLopez-Ibanez@users.noreply.github.com>
…3.12 Co-authored-by: MLopez-Ibanez <2620021+MLopez-Ibanez@users.noreply.github.com>
for more information, see https://pre-commit.ci
…ort-to-python-package # Conflicts: # python/src/moocore/_docsubstitute.py Co-authored-by: MLopez-Ibanez <2620021+MLopez-Ibanez@users.noreply.github.com>
Co-authored-by: MLopez-Ibanez <2620021+MLopez-Ibanez@users.noreply.github.com>
…ximise_to_bool_array return type Co-authored-by: MLopez-Ibanez <2620021+MLopez-Ibanez@users.noreply.github.com>
|
@copilot rebase on main branch, fix conflicts preferring the version in main always and revise your changes. I don't want to have a whole python/stub_gen.py script. The few missing stubs that cffi-stubgen cannot handle should be added explicitly. The generated stubs should also be added to the PR so they are committed to the repository. |
…ort-to-python-package # Conflicts: # python/src/moocore/_datasets.py # python/src/moocore/_moocore.py # python/src/moocore/_utils.py Co-authored-by: MLopez-Ibanez <2620021+MLopez-Ibanez@users.noreply.github.com>
…rrors Co-authored-by: MLopez-Ibanez <2620021+MLopez-Ibanez@users.noreply.github.com>
Done. Merged main (preferring main's version in all conflicts), removed |
Summary
Adds mypy static type checking via tox and fixes all 243 type errors across 5 Python source files in the
python/src/moocore/package.Changes
Configuration
python/pyproject.toml: Updatedpython_versionfrom3.11to3.12(required by current numpy 2.x stubs which usetypestatement syntax)Type fixes by file
_docsubstitute.py(3 errors fixed)TypeVar_Tandfrom typing import Any, TypeVar-> Noneto__init__, typed__call__with_TTypeVar to preserve decorated function types_ffi_build.py(7 errors fixed)get_config(),uses_msvc(),_get_target_platform()list[str]annotation toGCC_LDFLAGS_datasets.py(4 errors fixed)path: Path | strtype to_file_checksum.is_file()instead of.exists()(Traversable interface)cast(Path, ...)for return type narrowing**kwargs: Anytoget_dataset_utils.py(23 errors fixed)asarray_maybe_copywith explicitnp.ndarrayannotationnp2d_to_double_arrayandnp1d_to_c_arrayto avoid ArrayLike attribute accessunique_nosortreturn innp.asarray()is_integer_valueto returnbool_moocore.py(206 errors fixed)-> Noneto_check_dimension_maxread_datasetsto useos.fsdecode(always returnsstr)_parse_maximise_to_bool_arrayreturn type toAny(cffi CData)maximise→maximise_arrafter_parse_maximise()calls in all functions to avoid type reassignment conflictsfloat()ArrayLikeparameters being accessed with.shape,.min(), etc. by converting tonp.ndarrayfirstideal: ArrayLike = None→ideal: ArrayLike | None = Nonein multiple functionsidxreassignment conflicts by renaming toidx_sort/idx_groups**kwargs: Anytoapply_within_setsget_ideal,generate_ndsethelpers)_avg_hausdorff_dist_pythonto passmaximisecorrectly to_igd_python