Skip to content

fix(python): ship a PEP 561 py.typed marker and make the stubs mypy-clean - #243

Merged
jacobdenobel merged 1 commit into
IOHprofiler:masterfrom
bfs2021:fix/pep561-py-typed
Nov 6, 2026
Merged

jacobdenobel merged 1 commit into
IOHprofiler:masterfrom
bfs2021:fix/pep561-py-typed

Conversation

@bfs2021

@bfs2021 bfs2021 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Problem

The wheels ship .pyi stubs for the whole package, but no py.typed marker (PEP 561), so mypy ignores them and every ioh import degrades to Any (Skipping analyzing "ioh": module is installed, but missing library stubs or py.typed marker). Fixes #237.

Root cause

An empty ioh/py.typed is missing from the package. With the marker in place, mypy starts honouring the stubs — and then reports 22 errors in the stubs themselves, so the marker alone would trade one problem for another.

Fix

  • Add the empty ioh/py.typed; wheel.packages = ["ioh"] and the sdist's /ioh/ include pick it up with no packaging changes.
  • Fix the 22 stub errors the marker exposes:
    • wrap_problem, Experiment.__init__ and add_custom_problem: None defaults on parameters typed str / Callable / list → explicit | None;
    • Experiment.apply / add_custom_problem: any / callable used as types → typing.Any / typing.Callable[..., typing.Any];
    • iohcpp/logger/__init__.pyi: the property submodule was re-exported under the name property, shadowing the builtin decorator for every class-level @property in the file (9 × "Module not callable"); it is now imported by full path under a local alias;
    • iohcpp/problem/__init__.pyi: the 1-D and 2-D __call__ overloads were indistinguishable to mypy (the Annotated shape metadata is invisible to it), so the 2-D signature was reported as unreachable; the shape is now expressed in the ndarray type parameter;
    • MetaData.__eq__ widened to the object supertype signature, and the unhashable marker kept via an explicit ignore (mypy 2.x no longer accepts a bare __hash__ = None).

Testing

  • mypy -p ioh: 22 errors → Success: no issues found in 12 source files.
  • Simulated the installed-package experience with a stub-only copy (.pyi + py.typed, no compiled module): reveal_type(ioh.get_problem) now reports the full signature from the issue's expected output instead of Any.

…lean

The wheels carry .pyi stubs for the whole package but no py.typed
marker, so mypy ignored them and every ioh import degraded to Any. Add
the empty marker (both the wheel's packages list and the sdist include
pick it up from ioh/), and fix the errors the now-honoured stubs
themselves report:

- None defaults on parameters typed as str/Callable/list in
  wrap_problem, Experiment and add_custom_problem
- any/callable used as types in Experiment.apply/add_custom_problem
- the logger stub importing the property submodule under the name
  property, which shadowed the builtin decorator for every class-level
  @Property in the file
- __call__ overloads whose 1-D and 2-D variants were indistinguishable
  to mypy (shape is now expressed in the ndarray type parameter)
- MetaData.__eq__ widened to the object supertype signature

Fixes IOHprofiler#237
@jacobdenobel
jacobdenobel merged commit 985c297 into IOHprofiler:master Nov 6, 2026
1 check passed
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.

The wheels ship type stubs without a py.typed marker

2 participants