From 5858c3f92ce007988420048a8231118de41cfb35 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 4 Nov 2026 08:42:39 -0500 Subject: [PATCH] chore: Turn on all pyupgrade lints in ruff --- cuda_bindings_12/build_hooks.py | 12 ++++++------ cuda_bindings_12/cuda/bindings/utils/__init__.py | 3 ++- .../3_CUDA_Features/globalToShmemAsyncCopy_test.py | 2 +- cuda_bindings_12/setup.py | 3 +-- cuda_bindings_12/tests/nvml/test_init.py | 2 +- cuda_bindings_13/cuda/bindings/utils/__init__.py | 3 ++- cuda_bindings_13/cuda/bindings/utils/_nvvm_utils.py | 2 +- .../cuda/core/utils/_program_cache/_file_stream.py | 3 ++- cuda_core/cuda/core/utils/_program_cache/_keys.py | 3 ++- cuda_core/tests/graph/test_graph_node_update.py | 2 +- ruff.toml | 5 ----- samples/cuda_core/greenContext/greenContext.py | 13 ++++++------- .../processCheckpoint/processCheckpoint.py | 7 +++---- toolshed/find_skipped_tests.py | 2 +- 14 files changed, 29 insertions(+), 33 deletions(-) diff --git a/cuda_bindings_12/build_hooks.py b/cuda_bindings_12/build_hooks.py index 7258d7abf53..75a057b8907 100644 --- a/cuda_bindings_12/build_hooks.py +++ b/cuda_bindings_12/build_hooks.py @@ -352,12 +352,12 @@ def _parse_headers(header_dict, include_path_list, parser_caching): CUDA_VERSION = parser.defs["macros"].get("CUDA_VERSION", "Unknown") print(f"Found CUDA_VERSION: {CUDA_VERSION}", flush=True) - found_types += {key for key in parser.defs["types"]} - found_types += {key for key in parser.defs["structs"]} - found_types += {key for key in parser.defs["unions"]} - found_types += {key for key in parser.defs["enums"]} - found_functions += {key for key in parser.defs["functions"]} - found_values += {key for key in parser.defs["values"]} + found_types += {*parser.defs["types"]} + found_types += {*parser.defs["structs"]} + found_types += {*parser.defs["unions"]} + found_types += {*parser.defs["enums"]} + found_functions += {*parser.defs["functions"]} + found_values += {*parser.defs["values"]} for key, value in parser.defs["structs"].items(): struct_list[key] = _Struct(key, value["members"]) diff --git a/cuda_bindings_12/cuda/bindings/utils/__init__.py b/cuda_bindings_12/cuda/bindings/utils/__init__.py index 62d083dc7c6..2435d036b1f 100644 --- a/cuda_bindings_12/cuda/bindings/utils/__init__.py +++ b/cuda_bindings_12/cuda/bindings/utils/__init__.py @@ -1,7 +1,8 @@ # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -from typing import Any, Callable +from typing import Any +from collections.abc import Callable from ._ptx_utils import get_minimal_required_cuda_ver_from_ptx_ver, get_ptx_ver diff --git a/cuda_bindings_12/examples/3_CUDA_Features/globalToShmemAsyncCopy_test.py b/cuda_bindings_12/examples/3_CUDA_Features/globalToShmemAsyncCopy_test.py index 37a83047124..554f6f9e072 100644 --- a/cuda_bindings_12/examples/3_CUDA_Features/globalToShmemAsyncCopy_test.py +++ b/cuda_bindings_12/examples/3_CUDA_Features/globalToShmemAsyncCopy_test.py @@ -1200,7 +1200,7 @@ def main(): if kernel_number < 8: selected_kernel = kernels(kernel_number) else: - 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}") sys.exit(-1) major = checkCudaErrors( diff --git a/cuda_bindings_12/setup.py b/cuda_bindings_12/setup.py index 3566d931a64..0b33a569f9d 100644 --- a/cuda_bindings_12/setup.py +++ b/cuda_bindings_12/setup.py @@ -92,8 +92,7 @@ class TopLevelFinderWithRedirector(_TopLevelFinder): """Include the redirector files in the editable wheel.""" def get_implementation(self): - for item in super().get_implementation(): # noqa: UP028 - yield item + yield from super().get_implementation() with open(SITE_PACKAGES / REDIRECTOR_PTH) as f: yield (REDIRECTOR_PTH, f.read()) diff --git a/cuda_bindings_12/tests/nvml/test_init.py b/cuda_bindings_12/tests/nvml/test_init.py index 94b489ab45f..2be94434591 100644 --- a/cuda_bindings_12/tests/nvml/test_init.py +++ b/cuda_bindings_12/tests/nvml/test_init.py @@ -25,7 +25,7 @@ def test_devices_are_the_same_architecture(all_devices): # they won't be tested properly. This tests for the (hopefully rare) case # where a system has devices of different architectures and produces a warning. - all_arches = set(nvml.DeviceArch(nvml.device_get_architecture(device)) for device in all_devices) + all_arches = {nvml.DeviceArch(nvml.device_get_architecture(device)) for device in all_devices} if len(all_arches) > 1: warnings.warn( # noqa: B028 diff --git a/cuda_bindings_13/cuda/bindings/utils/__init__.py b/cuda_bindings_13/cuda/bindings/utils/__init__.py index 69618239d91..2c4c39b6d12 100644 --- a/cuda_bindings_13/cuda/bindings/utils/__init__.py +++ b/cuda_bindings_13/cuda/bindings/utils/__init__.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -from typing import Any, Callable +from collections.abc import Callable +from typing import Any from ._envvar import envvar_bool from ._nvvm_utils import check_nvvm_compiler_options diff --git a/cuda_bindings_13/cuda/bindings/utils/_nvvm_utils.py b/cuda_bindings_13/cuda/bindings/utils/_nvvm_utils.py index 9ac37c3a236..be5c4d58d40 100644 --- a/cuda_bindings_13/cuda/bindings/utils/_nvvm_utils.py +++ b/cuda_bindings_13/cuda/bindings/utils/_nvvm_utils.py @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -from typing import Sequence +from collections.abc import Sequence _PRECHECK_NVVM_IR = """target triple = "nvptx64-unknown-cuda" target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-i128:128:128-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64" diff --git a/cuda_core/cuda/core/utils/_program_cache/_file_stream.py b/cuda_core/cuda/core/utils/_program_cache/_file_stream.py index 8063d7e6c16..c2d46f1fe81 100644 --- a/cuda_core/cuda/core/utils/_program_cache/_file_stream.py +++ b/cuda_core/cuda/core/utils/_program_cache/_file_stream.py @@ -19,8 +19,9 @@ import tempfile import threading import time +from collections.abc import Callable, Iterable from pathlib import Path -from typing import Any, Callable, Iterable +from typing import Any from cuda.core._module import ObjectCode from cuda.core.utils._cache_dir import _default_cache_dir as _user_cache_dir diff --git a/cuda_core/cuda/core/utils/_program_cache/_keys.py b/cuda_core/cuda/core/utils/_program_cache/_keys.py index 2cf5b8913c8..56cc2f6d7c0 100644 --- a/cuda_core/cuda/core/utils/_program_cache/_keys.py +++ b/cuda_core/cuda/core/utils/_program_cache/_keys.py @@ -14,7 +14,8 @@ import abc import collections.abc import hashlib -from typing import Any, Callable, Sequence +from collections.abc import Callable, Sequence +from typing import Any # Mutual-dependency contract: this module imports ProgramOptions from # cuda.core._program at module level, and cuda.core._program imports diff --git a/cuda_core/tests/graph/test_graph_node_update.py b/cuda_core/tests/graph/test_graph_node_update.py index 0d31ceef1f9..e8e977771d9 100644 --- a/cuda_core/tests/graph/test_graph_node_update.py +++ b/cuda_core/tests/graph/test_graph_node_update.py @@ -8,8 +8,8 @@ import threading import time import weakref +from collections.abc import Callable from dataclasses import dataclass -from typing import Callable import pytest from helpers.graph_kernels import compile_common_kernels diff --git a/ruff.toml b/ruff.toml index 4dcc72d6eb5..7c1838481b8 100644 --- a/ruff.toml +++ b/ruff.toml @@ -52,11 +52,6 @@ select = [ ] ignore = [ - # typing backward compat — support older Python versions - "UP006", # non-pep585-annotation (e.g. Dict vs dict) - "UP007", # non-pep604-annotation (e.g. Union[X, Y] vs X | Y) - "UP035", # deprecated-import from typing - # security rules too strict for this project "S311", # allow random.* (not cryptographic) "S404", # allow subprocess imports diff --git a/samples/cuda_core/greenContext/greenContext.py b/samples/cuda_core/greenContext/greenContext.py index ea38f9c1bf2..a9145947608 100644 --- a/samples/cuda_core/greenContext/greenContext.py +++ b/samples/cuda_core/greenContext/greenContext.py @@ -57,7 +57,6 @@ import sys import time from dataclasses import dataclass -from typing import List, Tuple import numpy as np @@ -142,7 +141,7 @@ def _driver_accepts_split(sm, long_count: int, critical_count: int) -> bool: return actual == (long_count, critical_count) -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: """ Probe the driver for a (long, critical) split it actually accepts. @@ -174,14 +173,14 @@ def _find_working_split(sm, prefer_critical: int | None = None) -> Tuple[int, in while granularity * 2 <= total: base = max(granularity, _align_down(prefer_critical, granularity)) - candidates: List[int] = [] + candidates: list[int] = [] seen = set() # Default-arg binding captures the current loop iteration's values # (granularity, seen, candidates). push is never stored — it's only # called in this same iteration — but the explicit binding silences # ruff B023 and documents the intent. - def push(c: int, granularity: int = granularity, seen: set = seen, candidates: List[int] = candidates) -> None: + def push(c: int, granularity: int = granularity, seen: set = seen, candidates: list[int] = candidates) -> None: if c >= granularity and c <= total - granularity and c not in seen: seen.add(c) candidates.append(c) @@ -218,7 +217,7 @@ def _format_suggestion(sm, prefer_critical: int | None) -> str | None: return f"--split {long_count},{critical_count}" -def parse_split(arg: str | None, device: Device) -> Tuple[int, int]: +def parse_split(arg: str | None, device: Device) -> tuple[int, int]: """ Parse the --split "A,B" CLI argument and validate it against the device. @@ -487,7 +486,7 @@ def run_baseline( def run_green_context( device: Device, - split: Tuple[int, int], + split: tuple[int, int], delay_kernel, critical_kernel, delay_cycles: int, @@ -548,7 +547,7 @@ def _fmt_ms(value: float | None, width: int) -> str: return f"{value:>{width}.3f}" -def print_results(results: List[ScenarioResult]) -> None: +def print_results(results: list[ScenarioResult]) -> None: print() header = f"{'scenario':<32}{'SMs (long/crit)':>20}{'long (ms)':>14}{'crit total (ms)':>18}{'crit offset (ms)':>19}" print(header) diff --git a/samples/cuda_core/processCheckpoint/processCheckpoint.py b/samples/cuda_core/processCheckpoint/processCheckpoint.py index 06d180bf3f3..be2cd67b1fc 100644 --- a/samples/cuda_core/processCheckpoint/processCheckpoint.py +++ b/samples/cuda_core/processCheckpoint/processCheckpoint.py @@ -44,7 +44,6 @@ import sys import time from dataclasses import dataclass -from typing import List import numpy as np @@ -118,7 +117,7 @@ def _time_call(fn, *args, **kwargs) -> float: return (time.monotonic() - t0) * 1000.0 -def run_lifecycle(proc: checkpoint.Process, lock_timeout_ms: int) -> List[StepTiming]: +def run_lifecycle(proc: checkpoint.Process, lock_timeout_ms: int) -> list[StepTiming]: """ Drive the full `lock -> checkpoint -> restore -> unlock` cycle on `proc` and return per-step timings with the state observed after @@ -128,7 +127,7 @@ def run_lifecycle(proc: checkpoint.Process, lock_timeout_ms: int) -> List[StepTi the `locked` state. You must still call `unlock()` to return to `running`. """ - timings: List[StepTiming] = [StepTiming("initial", 0.0, proc.state)] + timings: list[StepTiming] = [StepTiming("initial", 0.0, proc.state)] ms = _time_call(proc.lock, timeout_ms=lock_timeout_ms) timings.append(StepTiming("lock", ms, proc.state)) @@ -145,7 +144,7 @@ def run_lifecycle(proc: checkpoint.Process, lock_timeout_ms: int) -> List[StepTi return timings -def print_timings(timings: List[StepTiming]) -> None: +def print_timings(timings: list[StepTiming]) -> None: print() header = f"{'step':<14}{'duration (ms)':>18}{'state after':>18}" print(header) diff --git a/toolshed/find_skipped_tests.py b/toolshed/find_skipped_tests.py index 1ad72eb8de6..cde779e020a 100755 --- a/toolshed/find_skipped_tests.py +++ b/toolshed/find_skipped_tests.py @@ -24,8 +24,8 @@ import subprocess import sys import tempfile +from collections.abc import Iterable from pathlib import Path -from typing import Iterable # Workflows to inspect, with the gh-api filter used to find the latest # completed run for each. The order here determines report ordering.