Skip to content

Add mypy type checking support and fix all type errors - #79

Closed
MLopez-Ibanez with Copilot wants to merge 8 commits into
mainfrom
copilot/add-mypy-support-to-python-package
Closed

MLopez-Ibanez with Copilot wants to merge 8 commits into
mainfrom
copilot/add-mypy-support-to-python-package

Conversation

Copilot AI commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

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: Updated python_version from 3.11 to 3.12 (required by current numpy 2.x stubs which use type statement syntax)

Type fixes by file

_docsubstitute.py (3 errors fixed)

  • Added TypeVar _T and from typing import Any, TypeVar
  • Added -> None to __init__, typed __call__ with _T TypeVar to preserve decorated function types

_ffi_build.py (7 errors fixed)

  • Added return type annotations to get_config(), uses_msvc(), _get_target_platform()
  • Added list[str] annotation to GCC_LDFLAGS

_datasets.py (4 errors fixed)

  • Added path: Path | str type to _file_checksum
  • Used .is_file() instead of .exists() (Traversable interface)
  • Added cast(Path, ...) for return type narrowing
  • Added **kwargs: Any to get_dataset

_utils.py (23 errors fixed)

  • Rewrote asarray_maybe_copy with explicit np.ndarray annotation
  • Fixed np2d_to_double_array and np1d_to_c_array to avoid ArrayLike attribute access
  • Wrapped unique_nosort return in np.asarray()
  • Fixed is_integer_value to return bool

_moocore.py (206 errors fixed)

  • Added -> None to _check_dimension_max
  • Fixed read_datasets to use os.fsdecode (always returns str)
  • Changed _parse_maximise_to_bool_array return type to Any (cffi CData)
  • Renamed maximisemaximise_arr after _parse_maximise() calls in all functions to avoid type reassignment conflicts
  • Wrapped all C library float returns with float()
  • Fixed ArrayLike parameters being accessed with .shape, .min(), etc. by converting to np.ndarray first
  • Fixed ideal: ArrayLike = Noneideal: ArrayLike | None = None in multiple functions
  • Fixed idx reassignment conflicts by renaming to idx_sort/idx_groups
  • Added **kwargs: Any to apply_within_sets
  • Added type annotations to private functions (get_ideal, generate_ndset helpers)
  • Fixed _avg_hausdorff_dist_python to pass maximise correctly to _igd_python

Copilot AI and others added 2 commits August 31, 2026 14:27
…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>
Copilot AI and others added 3 commits September 1, 2026 07:37
…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>
@MLopez-Ibanez

Copy link
Copy Markdown
Contributor

@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.

Copilot AI and others added 2 commits September 1, 2026 12:59
…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>

Copilot AI commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@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...

Done. Merged main (preferring main's version in all conflicts), removed stub_gen.py and the stubgen tox env, and committed the stubs directly to python/src/moocore/_libmoocore/lib/__init__.pyi with all 24 C function stubs and the integer constants. All type errors are fixed; tox -e type reports Success: no issues found in 8 source files.

@MLopez-Ibanez
MLopez-Ibanez deleted the copilot/add-mypy-support-to-python-package branch September 1, 2026 23:22
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