Skip to content

fix: assert hygiene -- unreachable assert, two caller-facing checks - #100

Open
petercorke wants to merge 1 commit into
mainfrom
fix/assert-hygiene
Open

fix: assert hygiene -- unreachable assert, two caller-facing checks#100
petercorke wants to merge 1 commit into
mainfrom
fix/assert-hygiene

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

Found while surveying src/'s ~48 Bandit B101 ("assert used") findings (see #99, which excludes tests/ from that check but leaves src/'s real findings active). Most are legitimate -- type-narrowing right after a prior check, or optional-dependency guards immediately following an ImportError raise -- and are staying as-is. Three were real issues:

  • Sources.py (PointCloud publish support): assert o3d is not None sat inside the if not _open3d_available: raise ImportError(...) block, after the raise -- unreachable dead code. Apparently a mis-indented copy of the same pattern used correctly at 7 other call sites in this file. Dedented to match them.
  • BundleAdjust.py: add_projection()'s assert len(uv) == 2, "uv must be a 2-vector" validates a caller-supplied argument on a public method, not an internal invariant -- converted to if len(uv) != 2: raise ValueError(...) so it survives python -O instead of silently vanishing.
  • Camera.py: nu/nv/width/height each asserted self._imagesize is not None, "imagesize not set" -- a real "you called this before configuring the camera" caller mistake (the informative message was the tell), not an internal invariant. Converted to if self._imagesize is None: raise ValueError(...), matching the existing raise ValueError("imagesize or rho properties not set") convention already used elsewhere in this file (Camera.py:1900).

Test plan

  • Full test suite: 1010 passed, 15 skipped, no regressions.

🤖 Generated with Claude Code

Found while surveying src/'s ~48 Bandit B101 (assert_used) findings; most
are legitimate (type-narrowing after a prior check, or optional-dependency
guards immediately following an ImportError raise) and are staying as-is.
Three were real issues:

- Sources.py (PointCloud publish support): `assert o3d is not None` sat
  *inside* the `if not _open3d_available: raise ImportError(...)` block,
  after the raise -- unreachable dead code, apparently a mis-indented
  copy of the same pattern used correctly at 7 other call sites in this
  file. Dedented to match.
- BundleAdjust.py: `add_projection()`'s `assert len(uv) == 2` validates a
  caller-supplied argument on a public method, not an internal invariant --
  converted to `if len(uv) != 2: raise ValueError(...)` so it survives
  `python -O` instead of silently vanishing.
- Camera.py: `nu`/`nv`/`width`/`height` each asserted
  `self._imagesize is not None, "imagesize not set"` -- a real "you called
  this before configuring the camera" caller mistake (the informative
  message was the tell), not an internal invariant. Converted to
  `if self._imagesize is None: raise ValueError(...)`, matching the
  existing `raise ValueError("imagesize or rho properties not set")`
  convention already used elsewhere in this file.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 10 complexity · 0 duplication

Metric Results
Complexity 10
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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