[Feature]: type check tests/, the last ignore_errors block
Search before asking
- I have searched the issues and discussions and found no similar feature request.
Feature Description
What: drop tests.* from the ignore_errors overrides in pyproject.toml so the test suite gets type checked too.
Why: #2091 set mypy up with examples.* and tests.* exempt, and the source side has been cleared out since (#2172 was the last of those). tests.* is the only block left. so here's what it actually costs, rather than guessing.
measured at 0080df0 with mypy 2.3.1 and the flags the pre-commit hook actually passes (--ignore-missing-imports --scripts-are-modules), each directory on its own with --follow-imports=silent. the source-only control comes back Success: no issues found in 90 source files, so none of this is my environment.
| directory | strict | without disallow_untyped_defs |
|---|---|---|
validators/ |
0 | 0 |
geometry/ |
2 | 1 |
classification/ |
4 | 4 |
cv2/ |
5 | 5 |
| root files | 10 | 9 |
draw/ |
21 | 21 |
annotators/ |
125 | 30 |
utils/ |
130 | 65 |
dataset/ |
150 | 140 |
key_points/ |
183 | 84 |
metrics/ |
219 | 103 |
detection/ |
332 | 307 |
| whole tree | 1192 | 780 |
there are two things i'd rather get your call on before writing any code.
there's a blocker you hit immediately. tests/annotators/test_utils.py:142 does from src.supervision.draw.color import ColorPalette, inside a test whose entire point is that the src namespace resolves. with mypy_path = src, mypy sees src/supervision/draw/color.py under two module names and gives up on the whole run:
error: Source file found twice under different module names:
"supervision.draw.color" and "src.supervision.draw.color"that's a module resolution error, not a line one, so # type: ignore does nothing for it. you either exclude that one file or reach the src namespace through importlib so mypy only ever sees one path. the second keeps the test meaningful but does change what it asserts, so it's your call. every number in the table above has that file excluded.
and one flag decides half the work. 565 of the 1192 are no-untyped-def, which is just -> None on test functions. it's most of the diff and it doesn't catch anything. the rest is the part that's actually worth having:
156 arg-type
157 attr-defined (mostly pytest.raises and mock.patch context managers)
106 union-attr
76 type-arg (bare ndarray)so, full strict on tests, or strict minus disallow_untyped_defs for tests.*? happy either way, i'd just rather agree it once than change my mind about it five directories in.
if you want this at all, validators/ is already clean and the next four are all under 25, so it can go in small increments the same way the source exemptions did.
Are you willing to submit a PR?
- Yes I'd like to help by submitting a PR!
Source: roboflow/supervision