Skip to content

chore(typing): add return-type annotations + enable disallow_incomplete_defs#582

Open
haoyu-haoyu wants to merge 1 commit into
allenai:mainfrom
haoyu-haoyu:typing/return-annotations
Open

chore(typing): add return-type annotations + enable disallow_incomplete_defs#582
haoyu-haoyu wants to merge 1 commit into
allenai:mainfrom
haoyu-haoyu:typing/return-annotations

Conversation

@haoyu-haoyu

Copy link
Copy Markdown

Summary

Adds return-type annotations to 29 functions across 11 files in scispacy/, and tightens mypy to catch this class of bug going forward.

Changes

  • 29 return-type annotations — all inferred from reading each function body (details in the diff).
  • pyproject.toml — added [tool.mypy] disallow_incomplete_defs = true. Rationale: the existing mypy invocation (mypy scispacy --ignore-missing-imports) did not flag partially-annotated functions (typed params + missing return type), which is how the 29 cases slipped through. disallow_incomplete_defs catches this without the broader fallout of disallow_untyped_defs (which would require annotating every function at once, including fully-unannotated legacy code).

Bug caught by the tighter config

scispacy/train_utils.py:evaluate_ner declared -> PerClassScorer but actually returns scorer.get_metric(), i.e. Dict[str, float]. Fixed the return type to match reality and added Collection[Tuple[str, Dict[str, Any]]] for the previously-untyped eval_data param. The only in-repo caller (scripts/evaluate_ner.py:38) ignores the return value, so no behavioral break.

Deliberately out of scope

  • disallow_untyped_defs — would surface dozens of unrelated unannotated functions; not this PR.

Test plan

  • bash scripts/mypy.shSuccess: no issues found in 20 source files
  • black scispacy --check --line-length 88 → no changes
  • flake8 scispacy → 0 errors
  • pytest tests/ (excluding tests needing en_core_sci_sm / nmslib locally): 26 passed

…te_defs

Annotate 29 functions across 11 files in scispacy/. Add
disallow_incomplete_defs to [tool.mypy] so partial annotations
(typed params + missing return) are flagged going forward. Fix
pre-existing wrong return type on train_utils.evaluate_ner
(declared PerClassScorer, actually returns Dict[str, float]).
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.

1 participant