Skip to content

build(pathfinder): let mypy see the package's own imports - #3622

Open
rparolin wants to merge 4 commits into
pathfinder-readability/15-canary-probe-modulefrom
pathfinder-readability/16-type-check-own-imports
Open

rparolin wants to merge 4 commits into
pathfinder-readability/15-canary-probe-modulefrom
pathfinder-readability/16-type-check-own-imports

Conversation

@rparolin

@rparolin rparolin commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

— codex on behalf of Ralf —

Description

Part 17 of 23 of a readability stack for cuda.pathfinder (stack: #3623 → #3602 → #3603 → #3604 → #3605 → #3606 → #3607 → #3608 → #3609 → #3610 → #3611 → #3613 → #3618 → #3619 → #3620 → #3621 → #3622 → #3627 → #3628 → #3629 → #3630 → #3631 → #3632). No behavior change.

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 three things:

  • Two cast() calls in header_descriptor.py are no longer needed; removed.
  • A real mismatch that was hidden, in the Linux loader and the Windows loader: load_with_abs_path accepted found_via: str | None = None and passed it to LoadedDL, which declares found_via: str. Every caller passes found_via (three calls in the loader, two in tests), so it is now a required str in both loaders and in the PlatformLoader protocol. No type: ignore is needed.
  • On Windows only: 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. Fixing it changes a declared type, so it is marked with a targeted type: ignore and a comment. unused-ignore is listed too, since the ignore is only needed on Windows.

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.

No runtime change for any caller in this repository. 1294 passed, 6 skipped. mypy passes for both --platform linux and --platform win32.

Testing

  • Full cuda_pathfinder test suite at this commit: 1294 passed, 6 skipped (Linux, Python 3.14).
  • pre-commit clean, including mypy-pathfinder.
  • Not run on Windows. Windows rules are exercised by tests that simulate Windows on Linux.

PLC Local Security Evidence (Advisory)

Local advisory checks only, run over the whole stack. Not release-gate results.

Check Status Tool Details
Secrets SKIP Pulse Secret Scanner scanner image not available locally (registry login); the repo trufflehog pre-commit hook passed
SAST WARN Semgrep 1 finding, not from this stack: the existing subprocess.run call in the canary probe, now in canary_probe.py
Dependencies WARN pip-audit / osv-scanner no manifest or lockfile in scope, so the local scan could not run; this stack changes no dependencies
License N/A - no dependencies changed
Container N/A - no container changed

Checklist

  • I have read the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

🤖 Generated with Claude Code

@rparolin
rparolin added this pull request to stack #3616 November 25, 2026 23:20
@copy-pr-bot

copy-pr-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.pathfinder Everything related to the cuda.pathfinder module label Nov 25, 2026
@rparolin rparolin added the enhancement Any code-related improvements label Nov 25, 2026
@rparolin rparolin added this to the cuda.pathfinder next milestone Nov 25, 2026
@rparolin rparolin self-assigned this Nov 25, 2026
@rparolin
rparolin requested review from juenglin and rwgk November 25, 2026 23:22
@rparolin
rparolin marked this pull request as ready for review November 26, 2026 15:43
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.

Next included review available in 27 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 12 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between aaaf45b and 2a4b60c.

Files selected for processing: 6

  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py
  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py
  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/platform_loader.py
  • cuda_pathfinder/cuda/pathfinder/_headers/header_descriptor.py
  • cuda_pathfinder/cuda/pathfinder/_utils/driver_info.py
  • cuda_pathfinder/pyproject.toml

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Chores
    • Tightened the library-loading interface: callers must now provide information about how a library was located. Type-checking configuration and diagnostics were also updated. These changes do not alter library-loading behavior or add user-facing features.

The mypy configuration now sets an import search path relative to its file. Loader methods require found_via as a string. Other source changes remove explicit casts and add type-checker suppressions.

Changes: Mypy type checks

Layer / File(s) Summary
Configure and update type checks
cuda_pathfinder/pyproject.toml, cuda_pathfinder/cuda/pathfinder/_dynamic_libs/*, cuda_pathfinder/cuda/pathfinder/_headers/header_descriptor.py, cuda_pathfinder/cuda/pathfinder/_utils/driver_info.py
The mypy configuration sets mypy_path relative to the configuration file. Linux and Windows loader signatures require found_via as a string. The driver loader call adds type-checker suppressions, and platform_include_subdirs removes explicit cast wrappers without changing its return values.

Suggested reviewers: cpcloud

Change: Other

Merge Risk: Minimal · previous review aaaf4

This PR tightens type checking for the pathfinder package and makes the found_via argument to the library loaders required. The author reports that every in-repository caller already supplies it, so no runtime impact is expected. The remaining risk is low and mostly concerns external callers that omit the argument.

Security architecture risk: Minimal · up to aaaf4

Both platform loaders now require callers to supply a discovery label. The package already supplies one on every path that uses these loaders. The public API and its library-loading behavior are unchanged, and the review found no new or increased security risk in this change.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Native loading still occurs inside the calling Python process. The changed signature does not add a path source, a caller, or loading privileges; the existing callers pass the same paths and labels as before.

Trust Boundaries and Controls

  • observed — The discovery label is not an authorization check. Linux keeps its existing label-dependent NVRTC preload rules, and Windows keeps its existing DLL directory handling and native load flags.
- [ ] 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 0f9c5b9 and aaaf45b.

Files selected for processing: 5

  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py
  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py
  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/platform_loader.py
  • cuda_pathfinder/cuda/pathfinder/_headers/header_descriptor.py
  • cuda_pathfinder/cuda/pathfinder/_utils/driver_info.py
Files skipped from review as they are similar to previous changes: 1

  • cuda_pathfinder/cuda/pathfinder/_utils/driver_info.py

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

@github-actions

Copy link
Copy Markdown
Contributor

rparolin and others added 4 commits November 26, 2026 11:17
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 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
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 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
`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 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
@rwgk
rwgk removed this pull request from stack #3616 November 26, 2026 19:19
@rwgk
rwgk force-pushed the pathfinder-readability/16-type-check-own-imports branch from 474f5a4 to 2a4b60c Compare November 26, 2026 19:19
@copy-pr-bot

copy-pr-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@rwgk
rwgk added this pull request to stack #3633 November 26, 2026 19:19

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.pathfinder Everything related to the cuda.pathfinder module enhancement Any code-related improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants