Skip to content

Reject booleans in range and array bounds validation#225

Merged
James Ball (james-ball-qualcomm) merged 3 commits into
mainfrom
copilot/sub-pr-223-again
Mar 19, 2026
Merged

Reject booleans in range and array bounds validation#225
James Ball (james-ball-qualcomm) merged 3 commits into
mainfrom
copilot/sub-pr-223-again

Conversation

Copilot AI commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Python's bool subclasses int, so isinstance(True, int) is True. This caused range: [0, true] and array: [0, true] to silently pass validation and render as "range 0 to True" instead of being rejected.

Changes

  • tools/shared_utils.py: Add not isinstance(..., bool) guards to both range bounds and array bounds validators, consistent with the existing width check pattern:

    # Before
    if isinstance(lo, int) and isinstance(hi, int):
    
    # After
    if isinstance(lo, int) and not isinstance(lo, bool) and isinstance(hi, int) and not isinstance(hi, bool):

    The error-path checks (not isinstance(lo, int)) are updated to not isinstance(lo, int) or isinstance(lo, bool) so booleans trigger the "non-integer value" fatal message.

  • tests/shared_utils/test_shared_utils.py: Add four fatal-case tests covering True as lo and hi in both range and array bounds.


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: james-ball-qualcomm <140646808+james-ball-qualcomm@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Addressing feedback on param type conversion in shared file Reject booleans in range and array bounds validation Mar 19, 2026
@james-ball-qualcomm James Ball (james-ball-qualcomm) marked this pull request as ready for review March 19, 2026 21:49
Copilot AI review requested due to automatic review settings March 19, 2026 21:49

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 tightens validation in infer_param_type_string() to reject boolean values in range and array bounds, preventing Python’s bool-is-int behavior from silently producing incorrect rendered type strings.

Changes:

  • Reject True/False in range bounds by adding explicit not isinstance(..., bool) guards (and adjusting the error-path checks accordingly).
  • Reject True/False in array bounds with the same non-bool integer validation pattern.
  • Add regression tests covering boolean lo/hi for both range and array fatal paths.

Reviewed changes

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

File Description
tools/shared_utils.py Harden range/array bounds validation to treat booleans as invalid integers and emit the existing “non-integer … value” fatal errors.
tests/shared_utils/test_shared_utils.py Add fatal-case test coverage to ensure boolean bounds are rejected for both range and array validation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: James Ball <jameball@qti.qualcomm.com>
@james-ball-qualcomm James Ball (james-ball-qualcomm) merged commit b2677e8 into main Mar 19, 2026
2 checks passed
@james-ball-qualcomm James Ball (james-ball-qualcomm) deleted the copilot/sub-pr-223-again branch March 19, 2026 21:53
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.

3 participants