Repository navigation
test(detection): type check remap_classes tests - #3022
Open
Pratik-Kumar-Dhakar wants to merge 2 commits into
Open
Pratik-Kumar-Dhakar wants to merge 2 commits into
Pratik-Kumar-Dhakar wants to merge 2 commits into
Conversation
Opt tests.detection.test_transform into strict mypy (roboflow#2618). Narrow the optional class_id, tracker_id and confidence fields and the class_name data value before reading them; no production code changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`Detections.mask` is `ndarray | CompactMask | None`; pre-commit.ci's mypy (numpy 2.4 stubs) rejects it as an `np.array_equal` argument. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the test type-narrowing and stricter mypy configuration changes.
No open issues 🎉
What changed in this PR
This PR advances #2618 by enabling strict mypy checking for the remaining exempt detection test module, tests.detection.test_transform. Changes are limited to test type narrowing and configuration; production code is unchanged.
Changes:
- Add explicit checks for optional fields and NumPy array values before test assertions use them.
- Include
tests.detection.test_transformin theignore_errors = falseoverride without relaxing type-checking settings.
| File | Description |
|---|---|
tests/detection/test_transform.py |
Narrow optional fields, class-name data, and masks before accessing array operations. |
pyproject.toml |
Enable strict type checking for the remap-classes test module. |
Review effort: Balanced
This branch has not been deployed
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.
Description
Part of #2618. This enables strict mypy for
tests.detection.test_transform, theremap_classestests added in #1846. It was the onlytests/detectionmodule still underignore_errors. Enabling it showed 15 errors, all of the same kind: optional fields anddata[...]values were read without narrowing.Motivation and Context
#2618 type checks
tests/one slice at a time. This file landed on Nov 13, after the detection slices, so nobody had picked it up. I lefttests/key_points/alone because it was claimed in the issue.Changes Made
assert ... is not Nonebefore reading the optionalclass_id,tracker_idandconfidencefields, as in test(detection): type check Detections core tests #2830.result.data["class_name"]is typedndarray | list, so it is now read into a local and checked withisinstance(..., np.ndarray)before.tolist().result.maskisndarray | CompactMask | None, so it is checked withisinstance(..., np.ndarray)before it is passed tonp.array_equal.pyproject.toml: the module joins theignore_errors = falseoverride, in sorted order.There are no production code changes and no relaxed settings. The existing
# type: ignore[arg-type]on the invalid-argument test is still needed, andwarn_unused_ignoresdoesn't flag it.Testing
mypy 2.4.1 with numpy 2.4.4, which reproduces pre-commit.ci's result exactly, reports
Success: no issues found in 242 source files. My first push missed the mask error because my local numpy stubs (2.5.5) are looser, and pre-commit.ci caught it. docformatter was run directly on Python 3.12, since the hooks pin 3.11, which I don't have locally.docs/changelog.mdunderUnreleased(type-only change, so no entry per AGENTS.md)Additional Notes
I used an AI coding assistant (Claude) to help make this change. I reviewed and ran everything myself and can answer questions about it.
🤖 Generated with Claude Code