Skip to content

chore: Turn on all pyupgrade lints in ruff - #3360

Merged
mdboom merged 2 commits into
NVIDIA:mainfrom
mdboom:pyupgrade
Nov 4, 2026
Merged

mdboom merged 2 commits into
NVIDIA:mainfrom
mdboom:pyupgrade

Conversation

@mdboom

@mdboom mdboom commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Currently in our ruff configuration, we enable all of the lints that come from pyupgrade (UP prefix) and then disable 3 specific rules in order to be backward compatible with the older Pythons that we still support. (pyupgrade is designed to help you upgrade your code to newer Python features, move off of deprecated things etc.) However, the UP checks in ruff are designed to automatically follow the target-version (currently set to 3.11 in our config) and automatically disable any lints that require a newer version of Python, so we should not be explicitly disabling rules.

The changes this introduces fall into these categories. Mostly these are performance improvements (though not necessarily in hot loops) -- but it's nice to have the lints in place to catch this kind of thing in hot loops in the future.

Star expansion

This is a performance improvement because it avoids Python looping.

-        found_values += {key for key in parser.defs["values"]}
+        found_types += {*parser.defs["types"]}

Favoring collections over typing

This isn't strictly necessary, but it prepares us for a future when the typing aliases are deprecated.

-from typing import Any, Callable
+from typing import Any
+from collections.abc import Callable

.format() with no arguments

This one detected a bona-fide bug -- that we were not interpolating a value into the message string. Only in an example, and in an error case, but still, always nice when a lint finds a real problem.

-            print("Error: kernel number should be between 0 to 7, you have entered %d".format())
+            print(f"Error: kernel number should be between 0 to 7, you have entered {kernel_number}")

Use yield from

This is another performance improvement (avoids a Python loop).

-        for item in super().get_implementation():  # noqa: UP028
-            yield item
+        yield from super().get_implementation()

Use built-ins as type annotations

This is purely a syntactic convenience.

-def _find_working_split(sm, prefer_critical: int | None = None) -> Tuple[int, int, int] | None:
+def _find_working_split(sm, prefer_critical: int | None = None) -> tuple[int, int, int] | None:

@mdboom mdboom self-assigned this Nov 4, 2026
@mdboom mdboom added the CI/CD CI/CD infrastructure label Nov 4, 2026
@mdboom mdboom added this to the CI milestone Nov 4, 2026
@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 Nov 4, 2026
@mdboom
mdboom requested a review from juenglin November 4, 2026 13:52
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Invalid kernel selections now display the entered kernel number in the error message.
  • Refactor
    • Updated Python type annotations and typing conventions across the project, including examples and utilities; runtime behavior is unchanged.
    • Simplified several internal parsing and iteration operations without changing their results.
  • Chores
    • Expanded lint checks for modern Python conventions.

The PR updates Python typing imports and annotations, enables three Ruff pyupgrade rules, simplifies several set and iterator expressions, and corrects an invalid-kernel error message.

Changes: Python typing updates

Layer / File(s) Summary
Typing syntax and lint rules
ruff.toml, cuda_bindings_12/cuda/bindings/utils/__init__.py, cuda_bindings_13/cuda/bindings/utils/*, cuda_core/cuda/core/utils/_program_cache/*, cuda_core/tests/graph/test_graph_node_update.py, samples/cuda_core/greenContext/greenContext.py, samples/cuda_core/processCheckpoint/processCheckpoint.py, toolshed/find_skipped_tests.py
Ruff no longer ignores UP006, UP007, and UP035. Typing imports use collections.abc, and sample annotations use built-in list and tuple types.

CUDA bindings simplifications

Layer / File(s) Summary
Binding parsing and iteration
cuda_bindings_12/build_hooks.py, cuda_bindings_12/setup.py, cuda_bindings_12/tests/nvml/test_init.py
The header parser adds mapping keys directly to sets. The import redirector uses yield from, and the NVML test uses a set comprehension.

Kernel error message

Layer / File(s) Summary
Invalid kernel message
cuda_bindings_12/examples/3_CUDA_Features/globalToShmemAsyncCopy_test.py
The error message interpolates the supplied kernel number instead of displaying the literal %d placeholder.

Suggested reviewers: danielfrg, rparolin

Change: Other

Merge Risk: Minimal · up to 08afa

The cleanup changes are compatible with the supported Python versions and pass the focused Ruff checks, with no identified merge-blocking risk.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 5858c3f and 08afa4b.

Files selected for processing: 6
  • cuda_core/cuda/core/utils/_program_cache/_file_stream.py
  • cuda_core/cuda/core/utils/_program_cache/_keys.py
  • cuda_core/tests/graph/test_graph_node_update.py
  • samples/cuda_core/greenContext/greenContext.py
  • samples/cuda_core/processCheckpoint/processCheckpoint.py
  • toolshed/find_skipped_tests.py
Files with no reviewable changes: 2
  • samples/cuda_core/processCheckpoint/processCheckpoint.py
  • samples/cuda_core/greenContext/greenContext.py

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

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor
Doc Preview CI
Preview removed because the pull request was closed or merged.

@mdboom
mdboom merged commit 43b44e6 into NVIDIA:main Nov 4, 2026
119 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 5, 2026
Removed preview folders for the following PRs:
- PR #3134
- PR #3240
- PR #3272
- PR #3326
- PR #3349
- PR #3352
- PR #3354
- PR #3360
- PR #3362
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/CD CI/CD infrastructure cuda.bindings Everything related to the cuda.bindings module cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants