Skip to content

Fix invalid type annotations (callable, np.array) in the package - #1438

Open
Michael-Duck wants to merge 1 commit into
huggingface:mainfrom
Michael-Duck:michael-duck/ai-759-fix-invalid-type-hints
Open

Michael-Duck wants to merge 1 commit into
huggingface:mainfrom
Michael-Duck:michael-duck/ai-759-fix-invalid-type-hints

Conversation

@Michael-Duck

@Michael-Duck Michael-Duck commented Oct 20, 2026 •

Copy link
Copy Markdown

Summary

The package used functions where a type was expected: callable as an annotation in Extractiveness.__init__ and in find_executable_batch_size, np.array (the constructor function, not the array type) as the return annotation of DropMetrics._align_bags, and a bare Annotated as the type of Arg.type. Type checkers reject all of them and typing.get_type_hints() cannot resolve them at runtime. This replaces them with typing.Callable, numpy.ndarray and typing.Any, and adds a regression test that scans every module of the package for annotations that do not refer to a type.

Notes

Only annotations change, runtime behaviour is unchanged. The new test is a static (ast-based) check: it needs no model, no GPU and no network access. Scope: this fixes the class of errors the issue points at - annotations that are not types - and guards against new ones; the ~1.2k remaining mypy errors reported in the issue are unrelated to it.

Tests

  • python3 -m pytest tests/unit/test_type_hints.py -q -> 285 passed. On the unmodified tree the same test reports 4 failed, 281 passed - one failure per file changed above: cli_args.py (bare Annotated), metrics/harness_compatibility/drop.py (np.array), metrics/metrics_sample.py (callable), utils/parallelism.py (callable).
  • ruff check src tests and ruff format --check src tests -> clean. The whole-repo ruff check . and ruff format --check . (what make quality runs) are clean too.
  • Wider suite: python -m pytest tests/ -q --ignore=tests/slow_tests -> 953 passed, 17 failed, 5 skipped. Those 17 failures are pre-existing and unrelated to this change: the identical set fails on the unmodified origin/main tree. They are 8 failures in tests/unit/tasks/test_registry.py (TypeError: HfApi.list_models() got an unexpected keyword argument 'model_name', a huggingface_hub API change) and 9 in tests/unit/models/vllm/test_vllm_model.py + tests/unit/utils/test_caching.py (vllm is not installed in the sandbox).
  • tests/slow_tests was not run: it downloads models and needs a GPU.

Fixes #759

Signed-off-by: Michael-Duck <michael@realms.nexus>
@Michael-Duck
Michael-Duck force-pushed the michael-duck/ai-759-fix-invalid-type-hints branch from 0a06bb8 to 058e121 Compare October 20, 2026 10:56
@Michael-Duck Michael-Duck changed the title Fix invalid type annotations used as types Fix invalid type annotations (callable, np.array) in the package Oct 20, 2026
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.

[BUG] incorrect type hints such as callable

1 participant