Skip to content

Refactor asserts and todos#2313

Draft
vikassaini77 wants to merge 25 commits into
roboflow:developfrom
vikassaini77:refactor-asserts-and-todos
Draft

Refactor asserts and todos#2313
vikassaini77 wants to merge 25 commits into
roboflow:developfrom
vikassaini77:refactor-asserts-and-todos

Conversation

@vikassaini77

Copy link
Copy Markdown
Contributor
Before submitting
  • Self-reviewed the code
  • Updated documentation, follow Google-style
  • Added docs entry for autogeneration (if new functions/classes)
  • Added/updated tests
  • All tests pass locally

Description

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • 🧪 Test update
  • 🔨 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🔧 Chore (dependencies, configs, etc.)

Motivation and Context

Closes #(issue)

Changes Made

Testing

  • I have tested this code locally
  • I have added unit tests that prove my fix is effective or that my feature works
  • All new and existing tests pass

Google Colab (optional)

Colab link:

Screenshots/Videos (optional)

Additional Notes

@vikassaini77 vikassaini77 requested a review from SkalskiP as a code owner June 12, 2026 13:34
@CLAassistant

CLAassistant commented Jun 12, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Borda

Borda commented Jun 12, 2026

Copy link
Copy Markdown
Member

Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

@vikassaini77 mind check pls ^^ 🦝

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.

Pull request overview

This PR refactors multiple runtime validations by replacing assert statements with explicit TypeError/ValueError raises, updates README formatting/structure, and adds a basic allowlist check before executing subprocess commands in an example script.

Changes:

  • Replaced assert-based validations with explicit exceptions across image utilities, keypoint annotators, VLM parsing, NMS utilities, converters, and line-zone logic.
  • Updated README.md structure (Table of Contents, heading capitalization, example placeholders, and minor HTML fixes).
  • Added a command allowlist guard before subprocess.run() in examples/time_in_zone/scripts/stream_from_file.py.

Holistic assessment (n/5):

  • Code quality: 3/5
  • Testing: 2/5
  • Documentation: 2/5

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/supervision/utils/image.py Replaces assert type/invariant checks with explicit exceptions in image helpers.
src/supervision/key_points/annotators.py Converts assert scene type checks to TypeError in annotators.
src/supervision/detection/vlm.py Replaces assert validations with exceptions in Florence-2 parsing.
src/supervision/detection/utils/iou_and_nms.py Replaces assert validations with ValueError in IoU/NMS utilities.
src/supervision/detection/utils/converters.py Replaces assert validations with ValueError in mask_to_rle.
src/supervision/detection/line_zone.py Converts internal assert invariants into explicit ValueErrors.
src/supervision/detection/core.py Replaces assert validations with exceptions in VLM dispatch + NMS/NMM paths.
README.md Adds a Table of Contents and cleans up headings/examples/HTML.
examples/time_in_zone/scripts/stream_from_file.py Adds an allowlist check before running subprocess commands.

Comment on lines +87 to +89
if command[0] not in ["docker", "ffmpeg"]:
raise ValueError(f"Command {command[0]} not allowed")
process = subprocess.run(command) # noqa: S603
Comment thread README.md
Comment on lines +27 to +38
## 📑 Table of Contents

- [👋 Hello](#-hello)
- [💻 Install](#-install)
- [🔥 Quickstart](#-quickstart)
- [Models](#models)
- [Annotators](#annotators)
- [Datasets](#datasets)
- [🎬 Tutorials](#-tutorials)
- [💜 Built with Supervision](#-built-with-supervision)
- [📚 Documentation](#-documentation)
- [🏆 Contribution](#-contribution)
Comment on lines +568 to +571
if not isinstance(result, str):
raise TypeError(
f"Expected string as <REGION_TO_CATEGORY> result, got {type(result)}"
)
Comment on lines +730 to +734
if not 0 <= iou_threshold <= 1:
raise ValueError(
"Value of `iou_threshold` must be in the closed range from 0 to 1, "
f"{iou_threshold} given."
)
Comment on lines +824 to +828
if not 0 <= iou_threshold <= 1:
raise ValueError(
"Value of `iou_threshold` must be in the closed range from 0 to 1, "
f"{iou_threshold} given."
)
Comment on lines +2504 to +2516
if self.confidence is None:
raise ValueError(
"Detections confidence must be given for NMS to be executed."
)

if class_agnostic:
predictions = np.hstack((self.xyxy, self.confidence.reshape(-1, 1)))
else:
assert self.class_id is not None, (
"Detections class_id must be given for NMS to be executed. If you"
" intended to perform class agnostic NMS set class_agnostic=True."
)
if self.class_id is None:
raise ValueError(
"Detections class_id must be given for NMS to be executed. If you"
" intended to perform class agnostic NMS set class_agnostic=True."
)
Comment on lines +2584 to +2596
if self.confidence is None:
raise ValueError(
"Detections confidence must be given for NMM to be executed."
)

if class_agnostic:
predictions = np.hstack((self.xyxy, self.confidence.reshape(-1, 1)))
else:
assert self.class_id is not None, (
"Detections class_id must be given for NMM to be executed. If you"
" intended to perform class agnostic NMM set class_agnostic=True."
)
if self.class_id is None:
raise ValueError(
"Detections class_id must be given for NMM to be executed. If you"
" intended to perform class agnostic NMM set class_agnostic=True."
)
Comment on lines 1153 to +1157
... )
>>> keep
array([ True, False])
"""
assert 0 <= iou_threshold <= 1, (
"Value of `iou_threshold` must be in the closed range from 0 to 1, "
f"{iou_threshold} given."
)
if not 0 <= iou_threshold <= 1:
Comment on lines +694 to +697
if mask.ndim != 2:
raise ValueError("Input mask must be 2D")
if mask.size == 0:
raise ValueError("Input mask cannot be empty")
@Borda Borda marked this pull request as draft June 14, 2026 23:00
@Borda

Borda commented Jun 18, 2026

Copy link
Copy Markdown
Member

@vikassaini77 pls follow the contribution guidelines. In particular, it means you shall write PR description why it does and how it fixes or improves this package, then you have to sign the CLA (or provide a screenshot of what you did), otherwise, we cannot move forward, even I see based on your changes a value in your contribution 🦝

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants