Skip to content

fix: assert used for input validation instead of proper error handling #1275

Description

Description

The assert unary_red_code in _EQUIVALENT_NON_NAN_OPS on line 42 is used to validate a function argument, not an internal invariant. When Python runs with the -O (optimize) flag, assert statements are stripped entirely. If a caller passes an invalid unary_red_code, the function will silently fall through to _EQUIVALENT_NON_NAN_OPS[unary_red_code] and raise a bare KeyError with no context about what went wrong or which inputs were invalid. For library code, argument validation should use explicit if/raise so it is never stripped by the interpreter. This also contradicts the project's own style guide ("Errors: try/except with raise").

Severity: medium
File: cupynumeric/_module/_unary_red_utils.py

Expected Behavior

The code should handle this case properly to avoid unexpected errors or degraded quality.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions