Skip to content

cuda.core: replace bare assert statements in library code with explicit errors #3202

Open

Description

@Andy-Jost

Follow-up to #2697, where @mdboom asked for all assert statements to leave the library (tests keep theirs), and @fedonman offered to convert them. #2704 handles the two in _memory/_ipc.pyx. This issue is the rest.

The inventory from #2697 (comment) still matches main (checked 2026-10-23): 15 remain, in _program.pyx, _module.pyx, _memoryview.pyx (five), _device.pyx, _memory/_managed_buffer.py, _memory/_managed_memory_resource.pyx, system/_device.pyx, system/_system_events.pyx, system/_field_values.pxi, and utils/_program_cache/ (two).

Conversion rules, from cuda_core/CLAUDE.md ("Failure handling"):

  • A check on a value that comes from outside (an argument, a producer's protocol answer, an NVML payload) raises ValueError or TypeError with a message that names the value.
  • An internal invariant raises RuntimeError("internal cuda.core error, please report: <what failed>").
  • assert False on an unreachable branch becomes the same RuntimeError.
  • Cython assert statements go too: Cython also drops them under -O.

To keep them out, enable ruff's S101 for library code: remove it from the global ignore list in ruff.toml and ignore it for **/tests/** only. The test suite keeps its asserts.

One PR after #2704 merges, so the two do not conflict. @fedonman, the offer in #2697 stands if you want it; say so here and I assign the issue to you.

Activity

  1. added this to the cuda.core 1.3.0 milestone on Oct 23, 2026
  2. added
    enhancementAny code-related improvements
    P2Low priority - Nice to have
    cuda.coreEverything related to the cuda.core module
    on Oct 23, 2026
  3. fedonman commented on Oct 26, 2026

    @fedonman
    Contributor

    Yes, I'd like to take it. #3223 is up. It doesn't touch any file that #2704 does, so it shouldn't need to wait for it.

  4. leofang commented on Oct 28, 2026

    @leofang
    Member

    @mdboom what is the reason that we don't like Python assert in cuda-core?

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

Metadata

Metadata

Assignees

Labels

P2Low priority - Nice to havecuda.coreEverything related to the cuda.core moduleenhancementAny code-related improvements

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions