From 11193ec50b321a246b3a40eb3ef47760c3a05eff Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Wed, 25 Nov 2026 16:19:34 -0700 Subject: [PATCH 1/4] build(pathfinder): let mypy see the package's own imports pre-commit runs mypy from the repository root with only a config file, so mypy could not resolve `cuda.pathfinder.*` imports and typed every name imported from another module in the package as `Any`. Type errors that cross a module boundary went unreported, and `cast()` calls were needed to quiet "returning Any" warnings. `mypy_path = "$MYPY_CONFIG_FILE_DIR"` points mypy at this directory whatever the working directory is. It works without the generated `_version.py`, as in CI. With imports resolved, mypy reports four things: - Two `cast()` calls in `header_descriptor.py` are no longer needed; removed. - Two real mismatches that were hidden: `load_with_abs_path` accepts `found_via: str | None` and passes it to `LoadedDL`, which declares `found_via: str`. Fixing that means changing a public annotation or a signature, so this change only marks both lines with a targeted `type: ignore` and a comment. Nothing else needed attention. No runtime change. 1293 passed, 6 skipped. Co-Authored-By: Claude Fable 5.2 Signed-off-by: Rob Parolin --- .../cuda/pathfinder/_dynamic_libs/load_dl_linux.py | 3 ++- .../cuda/pathfinder/_dynamic_libs/load_dl_windows.py | 3 ++- .../cuda/pathfinder/_headers/header_descriptor.py | 6 +++--- cuda_pathfinder/pyproject.toml | 3 +++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py index 5552b2296f47..dc24f4d5188b 100644 --- a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py +++ b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py @@ -244,4 +244,5 @@ def load_with_abs_path(desc: LibDescriptor, found_path: str, found_via: str | No raise RuntimeError(f"Failed to dlopen {found_path}: {e}") from e if desc.name == "nvrtc": _preload_nvrtc_builtins(found_path, found_via) - return LoadedDL(found_path, False, handle._handle, found_via) + # `found_via` is None when a caller omits it, but `LoadedDL` declares it as `str`. + return LoadedDL(found_path, False, handle._handle, found_via) # type: ignore[arg-type] diff --git a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py index 6e7220a19e74..437e6b6dff03 100644 --- a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py +++ b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py @@ -185,4 +185,5 @@ def load_with_abs_path(desc: LibDescriptor, found_path: str, found_via: str | No error_code = kernel32.GetLastError() raise RuntimeError(f"Failed to load DLL at {found_path}: Windows error {error_code}") - return LoadedDL(found_path, False, ctypes_handle_to_unsigned_int(handle), found_via) + # `found_via` is None when a caller omits it, but `LoadedDL` declares it as `str`. + return LoadedDL(found_path, False, ctypes_handle_to_unsigned_int(handle), found_via) # type: ignore[arg-type] diff --git a/cuda_pathfinder/cuda/pathfinder/_headers/header_descriptor.py b/cuda_pathfinder/cuda/pathfinder/_headers/header_descriptor.py index 3b108f618a5c..7a0c2d9f0797 100644 --- a/cuda_pathfinder/cuda/pathfinder/_headers/header_descriptor.py +++ b/cuda_pathfinder/cuda/pathfinder/_headers/header_descriptor.py @@ -13,7 +13,7 @@ import glob import os import sysconfig -from typing import TypeAlias, cast +from typing import TypeAlias from cuda.pathfinder._headers.header_descriptor_catalog import ( HEADER_DESCRIPTOR_CATALOG, @@ -34,8 +34,8 @@ def platform_include_subdirs(desc: HeaderDescriptor) -> tuple[str, ...]: common subdirs. On Linux, only the common subdirs are returned. """ if IS_WINDOWS: - return cast(tuple[str, ...], desc.include_subdirs_windows + desc.include_subdirs) - return cast(tuple[str, ...], desc.include_subdirs) + return desc.include_subdirs_windows + desc.include_subdirs + return desc.include_subdirs def system_install_dir_patterns(desc: HeaderDescriptor) -> tuple[str, ...]: diff --git a/cuda_pathfinder/pyproject.toml b/cuda_pathfinder/pyproject.toml index 904463b7022f..bb62faae7a66 100644 --- a/cuda_pathfinder/pyproject.toml +++ b/cuda_pathfinder/pyproject.toml @@ -129,6 +129,9 @@ markers = [ # Basic settings python_version = "3.11" explicit_package_bases = true +# Resolve `cuda.pathfinder` imports from this directory whatever the working +# directory is. Without it the package's own imports are typed as `Any`. +mypy_path = "$MYPY_CONFIG_FILE_DIR" warn_return_any = true warn_unused_configs = true disallow_untyped_defs = true From b4e47a4205912570bf186d199670c86f06fc76d9 Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Wed, 25 Nov 2026 16:34:55 -0700 Subject: [PATCH 2/4] build(pathfinder): mark a Windows-only type mismatch in driver_info With the package's imports visible, mypy on Windows reports one more real mismatch: `LoadedDL.abs_path` is typed `str | None`, and it is passed to the Windows driver loader, which is declared to take `str`. Linux does not analyse that branch, so only the Windows pre-commit job caught it. Like the other two, it is marked with a targeted `type: ignore` and a comment rather than fixed, because fixing it changes a declared type. `unused-ignore` is listed too, since the ignore is only needed on Windows. No runtime change. mypy passes for both `--platform linux` and `--platform win32`. Co-Authored-By: Claude Fable 5.2 Signed-off-by: Rob Parolin --- cuda_pathfinder/cuda/pathfinder/_utils/driver_info.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cuda_pathfinder/cuda/pathfinder/_utils/driver_info.py b/cuda_pathfinder/cuda/pathfinder/_utils/driver_info.py index d07c4b861d34..95a392abebe3 100644 --- a/cuda_pathfinder/cuda/pathfinder/_utils/driver_info.py +++ b/cuda_pathfinder/cuda/pathfinder/_utils/driver_info.py @@ -69,7 +69,8 @@ def query_driver_cuda_version() -> DriverCudaVersion: def _query_driver_cuda_version_int() -> int: """Return the encoded CUDA driver version from ``cuDriverGetVersion()``.""" loaded_cuda = _load_nvidia_dynamic_lib("cuda") - driver_lib = _DRIVER_LIB_LOADER(loaded_cuda.abs_path) + # `LoadedDL.abs_path` is typed `str | None`, but the Windows loader is declared to take `str`. + driver_lib = _DRIVER_LIB_LOADER(loaded_cuda.abs_path) # type: ignore[arg-type, unused-ignore] cu_driver_get_version = driver_lib.cuDriverGetVersion cu_driver_get_version.argtypes = [ctypes.POINTER(ctypes.c_int)] cu_driver_get_version.restype = ctypes.c_int From c01eda9e60a033e24bcd7e11bbf5ac99af7df3c3 Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Thu, 26 Nov 2026 10:34:19 -0700 Subject: [PATCH 3/4] refactor(pathfinder): make `found_via` a required loader argument `load_with_abs_path` took `found_via: str | None = None`, but `LoadedDL` declares `found_via` as `str`. This change had papered over the mismatch with two `# type: ignore[arg-type]` lines. Every caller passes `found_via`: three calls in `load_nvidia_dynamic_lib.py` and two in tests. So the parameter is now a required `str` in the Linux loader, the Windows loader and the `PlatformLoader` protocol, and both ignore lines are gone. mypy passes for Linux and for `--platform win32`. Risk: `load_with_abs_path` is a private function. A caller outside this repository that omits `found_via` would now get a `TypeError` instead of a `LoadedDL` whose `found_via` is `None`. Co-Authored-By: Claude Fable 5.2 Signed-off-by: Rob Parolin --- .../cuda/pathfinder/_dynamic_libs/load_dl_linux.py | 7 +++---- .../cuda/pathfinder/_dynamic_libs/load_dl_windows.py | 5 ++--- .../cuda/pathfinder/_dynamic_libs/platform_loader.py | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py index dc24f4d5188b..4a6d0c75caef 100644 --- a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py +++ b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py @@ -188,7 +188,7 @@ def load_with_system_search(desc: LibDescriptor) -> LoadedDL | None: return None -def _preload_nvrtc_builtins(found_path: str, found_via: str | None) -> None: +def _preload_nvrtc_builtins(found_path: str, found_via: str) -> None: # Let Conda packaging provide sibling lookup through RPATH. if found_via == FOUND_VIA_CONDA: return @@ -224,7 +224,7 @@ def _preload_nvrtc_builtins(found_path: str, found_via: str | None) -> None: ) -def load_with_abs_path(desc: LibDescriptor, found_path: str, found_via: str | None = None) -> LoadedDL: +def load_with_abs_path(desc: LibDescriptor, found_path: str, found_via: str) -> LoadedDL: """Load a dynamic library from the given path. Args: @@ -244,5 +244,4 @@ def load_with_abs_path(desc: LibDescriptor, found_path: str, found_via: str | No raise RuntimeError(f"Failed to dlopen {found_path}: {e}") from e if desc.name == "nvrtc": _preload_nvrtc_builtins(found_path, found_via) - # `found_via` is None when a caller omits it, but `LoadedDL` declares it as `str`. - return LoadedDL(found_path, False, handle._handle, found_via) # type: ignore[arg-type] + return LoadedDL(found_path, False, handle._handle, found_via) diff --git a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py index 437e6b6dff03..79e3f4a946b6 100644 --- a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py +++ b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py @@ -161,7 +161,7 @@ def load_with_system_search(desc: LibDescriptor) -> LoadedDL | None: return None -def load_with_abs_path(desc: LibDescriptor, found_path: str, found_via: str | None = None) -> LoadedDL: +def load_with_abs_path(desc: LibDescriptor, found_path: str, found_via: str) -> LoadedDL: """Load a dynamic library from the given path. Args: @@ -185,5 +185,4 @@ def load_with_abs_path(desc: LibDescriptor, found_path: str, found_via: str | No error_code = kernel32.GetLastError() raise RuntimeError(f"Failed to load DLL at {found_path}: Windows error {error_code}") - # `found_via` is None when a caller omits it, but `LoadedDL` declares it as `str`. - return LoadedDL(found_path, False, ctypes_handle_to_unsigned_int(handle), found_via) # type: ignore[arg-type] + return LoadedDL(found_path, False, ctypes_handle_to_unsigned_int(handle), found_via) diff --git a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/platform_loader.py b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/platform_loader.py index 283578fcfa84..ab0c881aa087 100644 --- a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/platform_loader.py +++ b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/platform_loader.py @@ -28,7 +28,7 @@ def check_if_already_loaded_from_elsewhere(self, desc: LibDescriptor) -> LoadedD def load_with_system_search(self, desc: LibDescriptor) -> LoadedDL | None: ... - def load_with_abs_path(self, desc: LibDescriptor, found_path: str, found_via: str | None = None) -> LoadedDL: ... + def load_with_abs_path(self, desc: LibDescriptor, found_path: str, found_via: str) -> LoadedDL: ... if sys.platform == "win32": From 2a4b60c4603a7d8260a09be21fdb15bf5ec7c398 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 26 Nov 2026 11:17:28 -0800 Subject: [PATCH 4/4] ci: require manual copy-pr-bot approval Signed-off-by: Ralf W. Grosse-Kunstleve