Skip to content

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

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

rparolin wants to merge 1 commit 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 →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 02e00f7 and 91a8678.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Chores
    • Library-loading calls now require callers to specify how the library was located; omitting this information is no longer supported.
    • Updated type-checking configuration and diagnostics. 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, mdboom

Change: Other

Merge Risk: Minimal · previous review b354c

This change tightens type checking for the pathfinder package and requires a discovery-source argument when loading libraries by absolute path. Library loading behavior is unchanged for in-repository callers, so merge risk is minimal.

Security architecture risk: Minimal · up to b354c

cuda.pathfinder now requires its internal loader calls to pass the discovery label they already provide. Applications using the public API do not need to change. Code that directly calls the private helper without the label will now receive a TypeError before the helper attempts to load a library.

- [ ] 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 4347874 and b354cb2.

Files selected for processing: 3

  • 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; 5 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

@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
@rparolin

rparolin commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test b354cb2

@rparolin
rparolin force-pushed the pathfinder-readability/16-type-check-own-imports branch from b354cb2 to 02e00f7 Compare December 4, 2026 17:54
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>
@rparolin
rparolin force-pushed the pathfinder-readability/16-type-check-own-imports branch from 02e00f7 to 91a8678 Compare December 4, 2026 20:44

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