Skip to content

test(detection): type check remap_classes tests - #3022

Open
Pratik-Kumar-Dhakar wants to merge 2 commits into
roboflow:developfrom
Pratik-Kumar-Dhakar:test/type-check-transform-tests
Open

Pratik-Kumar-Dhakar wants to merge 2 commits into
roboflow:developfrom
Pratik-Kumar-Dhakar:test/type-check-transform-tests

Conversation

@Pratik-Kumar-Dhakar

@Pratik-Kumar-Dhakar Pratik-Kumar-Dhakar commented Nov 18, 2026 •

Copy link
Copy Markdown

Description

Part of #2618. This enables strict mypy for tests.detection.test_transform, the remap_classes tests added in #1846. It was the only tests/detection module still under ignore_errors. Enabling it showed 15 errors, all of the same kind: optional fields and data[...] 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 left tests/key_points/ alone because it was claimed in the issue.

Changes Made

  • assert ... is not None before reading the optional class_id, tracker_id and confidence fields, as in test(detection): type check Detections core tests #2830.
  • result.data["class_name"] is typed ndarray | list, so it is now read into a local and checked with isinstance(..., np.ndarray) before .tolist().
  • result.mask is ndarray | CompactMask | None, so it is checked with isinstance(..., np.ndarray) before it is passed to np.array_equal.
  • pyproject.toml: the module joins the ignore_errors = false override, 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, and warn_unused_ignores doesn't flag it.

Testing

mypy (all files, as pre-commit.ci runs it)  # 15 errors in this file once opted in, 0 with this PR
pytest tests/detection/test_transform.py    # 17 passed (same as develop)
pre-commit run ruff-check ruff-format codespell pyproject-fmt --files <changed>   # all pass

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.

  • Added/updated tests, and the full suite passes locally
  • Updated docs (docstrings / mkdocs entry) for new or changed public API (not applicable)
  • Added a changelog entry in docs/changelog.md under Unreleased (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

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>
@Borda
Borda requested a balanced review from Copilot November 18, 2026 20:10
@Borda Borda added the enhancement New feature or request label Nov 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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_transform in the ignore_errors = false override 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants