chore(typing): add return-type annotations + enable disallow_incomplete_defs#582
Open
haoyu-haoyu wants to merge 1 commit into
Open
chore(typing): add return-type annotations + enable disallow_incomplete_defs#582haoyu-haoyu wants to merge 1 commit into
haoyu-haoyu wants to merge 1 commit into
Conversation
…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]).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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_defscatches this without the broader fallout ofdisallow_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_nerdeclared-> PerClassScorerbut actually returnsscorer.get_metric(), i.e.Dict[str, float]. Fixed the return type to match reality and addedCollection[Tuple[str, Dict[str, Any]]]for the previously-untypedeval_dataparam. 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.sh→Success: no issues found in 20 source filesblack scispacy --check --line-length 88→ no changesflake8 scispacy→ 0 errorspytest tests/(excluding tests needingen_core_sci_sm/nmsliblocally): 26 passed