Skip to content

chore: Use Python match statement where possible - #3114

Open
mdboom wants to merge 1 commit into
NVIDIA:mainfrom
mdboom:match-statement
Open

mdboom wants to merge 1 commit into
NVIDIA:mainfrom
mdboom:match-statement

Conversation

@mdboom

@mdboom mdboom commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Now that Python 3.10 is long in the past, we can rely on a robust implementation of the match statement. I had my agent find candidates and update them -- most of what it found was in test code, but I thought it best to leave that alone.

@github-actions github-actions Bot added cuda.bindings Everything related to the cuda.bindings module cuda.core Everything related to the cuda.core module labels Oct 14, 2026
@mdboom mdboom self-assigned this Oct 14, 2026
@mdboom mdboom added the enhancement Any code-related improvements label Oct 14, 2026
@mdboom mdboom added this to the cuda.core next milestone Oct 14, 2026
@coderabbitai

coderabbitai Bot commented Oct 14, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/cuda-python/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 90d3373e-336e-47dd-be9d-31bf1c2a643c
📥 Commits

Reviewing files that changed from the base of the PR and between 1f41281 and 1230917.

📒 Files selected for processing: 5
  • cuda_core/cuda/core/utils/_program_cache/_keys.py
  • samples/cuda_bindings/3_CUDA_Features/globalToShmemAsyncCopy/globalToShmemAsyncCopy.py
  • samples/cuda_bindings/4_CUDA_Libraries/nvidiaSmi/nvidiaSmi.py
  • samples/cuda_core/glInteropMipmapLod/glInteropMipmapLod.py
  • toolshed/check_cython_abi.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 9 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Refactor
    • Updated the handling of CUDA sample selections, keyboard controls, and NVML compute-mode labels. Existing sample behavior and displayed labels remain unchanged, including fallback handling for unrecognized modes.
    • Updated supporting utilities to process source values and Cython declarations with equivalent results. These changes do not alter the available features or outputs.

The pull request replaces conditional chains with Python match/case in five code paths. The summaries report that the existing launch configurations, mappings, key handling, and parsing results remain unchanged.

Changes: Pattern-Matching Refactors

Layer / File(s) Summary
CUDA kernel launch dispatch
samples/cuda_bindings/3_CUDA_Features/globalToShmemAsyncCopy/globalToShmemAsyncCopy.py
The warmup and timed dispatches use match/case for all eight kernel choices. Their launch configurations, including the shared-state dimensions, remain unchanged.
Sample input and compute-mode dispatch
samples/cuda_core/glInteropMipmapLod/glInteropMipmapLod.py, samples/cuda_bindings/4_CUDA_Libraries/nvidiaSmi/nvidiaSmi.py
Keyboard handling uses match/case while retaining bias adjustments and reset behavior. NVML compute-mode labels use match/case, with the existing N/A error fallback retained.
Cache encoding and ABI parsing
cuda_core/cuda/core/utils/_program_cache/_keys.py, toolshed/check_cython_abi.py
Extra-source encoding and Cython node classification use match/case. The described encoding, field extraction, and result mappings remain unchanged.

Priority: ⬇️ Low

Change: Refactor

Merge Risk: ⚪ Minimal · up to 12309

No actionable merge-blocking risk remains.

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

This branch has not been deployed

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

Labels

cuda.bindings Everything related to the cuda.bindings module cuda.core Everything related to the cuda.core module enhancement Any code-related improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants