supervision icon indicating copy to clipboard operation
supervision copied to clipboard

[Feature]: type check tests/, the last ignore_errors block

Open atikulmunna opened this issue 2 months ago • 9 comments

Search before asking

  • [x] 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?

  • [x] Yes I'd like to help by submitting a PR!

atikulmunna avatar Sep 22 '26 12:09 atikulmunna

I’m interested in working on this. Would you prefer full strict typing for tests, including return annotations on test functions, or strict typing without disallow_untyped_defs? Also, for tests/annotators/test_utils.py, should we keep the test’s src.supervision import and exclude that file from mypy, or adjust the import so the file can be checked? I can start with the already-clean validators/ directory and proceed incrementally.

abhinav-TB avatar Oct 01 '26 03:10 abhinav-TB

Hi, I'd like to contribute to issue #2618 by taking a small, focused part of the remaining test type-checking work.

I’m considering starting with tests/annotators/. Before I begin, could you clarify whether the expectation is full strict typing, including disallow_untyped_defs, or whether relaxing that specific check for tests is acceptable?

I’ll first reproduce and document the Mypy errors, then submit a scoped PR with the relevant fixes and configuration changes. Please let me know if anyone is already working on this directory.

buildwithshlok avatar Oct 21 '26 00:10 buildwithshlok

Hi, would it be useful for me to take a small follow-up slice of this: tests/utils/test_conversion.py and tests/utils/test_iterables.py?

I checked the current open PRs, including #2784, and have a local draft limited to those two files plus their exact ignore_errors = false entries in pyproject.toml. It preserves the existing runtime scenarios and assertions, adds accurate annotations and Pillow type narrowing, and does not change production code or relax the strict settings.

On develop b4225e5, enabling just those modules exposes 3 errors with the configured pre-commit mypy environment, and 11 when mypy uses the complete development environment. The local draft clears both sets. On Windows CPU, the full suite retains the baseline's 5913 passed / 133 skipped, and all-file pre-commit passes. The two target modules pass both without OpenCV (37 passed / 1 skipped) and with OpenCV (38 passed / no skips), matching the unchanged baseline in each environment.

@abhinav-TB, are you already working on either of these files? I'd like to avoid overlapping with your remaining work. This is only a two-module slice; I am not taking the entire utils package. AI assistance was used to prepare the local draft.

NaCr05 avatar Oct 22 '26 16:10 NaCr05

Sounds good! My PR #2784 is scoped strictly to tests.annotators.* (plus tests/helpers.py), so there is no overlap with tests/utils/ on my end. Feel free to go ahead with that slice!"

buildwithshlok avatar Oct 22 '26 16:10 buildwithshlok

Hi! I'd like to take a separate slice: a few files from tests/key_points/. I've seen #2728, #2784 and NaCr05's utils slice, so I'll stay out of those. I'll follow the strict settings #2728 uses (annotations and narrowing only, no relaxing) with a specific ignore_errors = false override per module, and no production-code changes. @abhinav-TB, are you on key_points, dataset, detection or metrics?

danielking-debug avatar Oct 24 '26 08:10 danielking-debug

Claiming tests/dataset/ for the next slice — the whole package, i.e. tests/dataset/test_core.py, test_progress.py, test_utils.py and tests/dataset/formats/{test_coco,test_createml,test_labelme,test_pascal_voc,test_yolo}.py, plus the "tests.dataset.*" entry in the ignore_errors = false override.

Checked against what is already claimed: @kevin9327 took the root helpers + assets/classification/cv2/depth/draw/geometry/validators (#2728), @buildwithshlok took tests/annotators/* + tests/helpers.py (#2784), @NaCr05 has tests/utils/test_conversion.py and tests/utils/test_iterables.py, and @danielking-debug has files in tests/key_points/. So I'm staying off detection/, metrics/, key_points/ and utils/ — metrics/ (261 errors) and detection/ (362) are still free for whoever wants them.

For reference, with "tests.dataset.*" flipped to ignore_errors = false the folder starts at 182 errors in 8 files. I'm keeping full strict (no disallow_untyped_defs opt-out), same as the merged slices.

mh-masum6875 avatar Oct 24 '26 19:10 mh-masum6875

I'd like to take a small tests/metrics slice of #2618: test_core.py, test_lazy_imports.py, and coco_reference.py, plus exact ignore_errors = false overrides for those modules. On current develop (b651cca), mypy 2.4.0 with the project's strict settings reports 4, 6, and 4 errors respectively when tests.metrics.* is enabled. I'll preserve test behavior and leave the rest of tests/metrics untouched. I checked the open PRs and issue comments for overlap. Please let me know if this scope conflicts with work already underway; I'll wait for maintainer agreement before opening the PR.

mh-masum6875 avatar Oct 25 '26 05:10 mh-masum6875

Following #2809 and #2815, I'd like to take the remaining utils slice: tests/utils/test_video.py, plus its exact tests.utils.test_video opt-in in pyproject.toml.

On current develop (d3a07a5), enabling that module exposes 57 mypy errors in both the configured hook environment and the complete development environment. A local candidate clears both sets with accurate frame/callback annotations, typed capture and queue test doubles, and a typed deadline helper. It preserves the existing test cases and assertions, without changing production code or relaxing strict settings.

All-file pre-commit passes. The full Windows CPU suite retains the baseline's 6,227 passed / 205 skipped with the fallback backend, and all 110 existing video tests pass with OpenCV. Testcase identities and outcomes match the baseline in both runs. I checked the current open PR file lists and issue claims and found no overlap with this file. Please let me know if someone already has unpublished work on this slice.

AI assistance: Codex prepared the local changes, validation, and this scope note; a separate Codex agent reviewed the diff and checked that the existing test identities, parameters, and assertions were preserved.

NaCr05 avatar Oct 29 '26 14:10 NaCr05