Skip to content

fix: replace input-validation asserts with explicit raises for PYTHONOPTIMIZE=1 compatibility#106

Draft
janickm wants to merge 1 commit into
NVIDIA:mainfrom
janickm:cosmic-narwhal
Draft

fix: replace input-validation asserts with explicit raises for PYTHONOPTIMIZE=1 compatibility#106
janickm wants to merge 1 commit into
NVIDIA:mainfrom
janickm:cosmic-narwhal

Conversation

@janickm
Copy link
Copy Markdown
Collaborator

@janickm janickm commented May 11, 2026

Summary

  • Converts ~160 assert statements used for input validation to explicit if/raise ValueError/TypeError/FileNotFoundError across the codebase so that validation is not silently stripped under PYTHONOPTIMIZE=1 (python -O).
  • True invariants (internal post-conditions indicating bugs in our own code) are preserved as assert.
  • Test expectations updated from assertRaises(AssertionError) to assertRaises(ValueError) / assertRaises(TypeError) where production code changed.

Files changed (16)

Production code (13 files):

  • ncore/impl/common/transformations.py — interval, pose interpolator, point cloud transform validation
  • ncore/impl/common/util.py — file/directory existence checks
  • ncore/impl/data/compat.py — frame time range validation
  • ncore/impl/data/types.py — all dataclass __post_init__ field validation
  • ncore/impl/data/v4/compat.py — component group name validation (from prior PR)
  • ncore/impl/data/v4/components.py — pose, sensor frame, point cloud, label storage validation
  • ncore/impl/sensors/camera.py — constructor fields, argument shapes/dtypes/timestamps
  • ncore/impl/sensors/common.py — overflow checks, newton iterations, quaternion shapes
  • ncore/impl/sensors/lidar.py — argument shapes/dtypes/timestamps
  • ncore/impl/data_converter/base.py — sensor ID subset validation
  • tools/data_converter/colmap/converter.py — camera type validation
  • tools/data_converter/pai/converter.py — pose count, platform class validation
  • tools/data_converter/waymo/converter.py — frame count validation
  • tools/ncore_project_pc_to_img.py — CLI parameter validation

Test code (3 files):

  • ncore/impl/common/transformations_test.py
  • ncore/impl/data/v4/components_test.py
  • ncore/impl/sensors/camera_test.py

Verification

All 28 test targets pass both with and without PYTHONOPTIMIZE=1:

bazel test //... --test_env=PYTHONOPTIMIZE=1 --config=no-gpu  # 28 pass
bazel test //... --config=no-gpu                                # 28 pass

@janickm janickm self-assigned this May 11, 2026
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 11, 2026

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

…OPTIMIZE=1 compatibility

Convert ~160 assert statements used for input validation to explicit
if/raise ValueError/TypeError/FileNotFoundError across 16 files.
This ensures validation is not silently stripped when running with
python -O (PYTHONOPTIMIZE=1).

True invariants (internal post-conditions that indicate bugs) are
preserved as assert statements.

Tests updated to expect ValueError/TypeError instead of AssertionError
where the production code was changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant