Skip to content

refactor: fix type errors that pyrefly 1.4 reports in whitelisted files - #5296

Merged
yuki-97 merged 1 commit into
mainfrom
rnabel/pyrefly-prep-fixes
Nov 19, 2026
Merged

yuki-97 merged 1 commit into
mainfrom
rnabel/pyrefly-prep-fixes

Conversation

@RNabel

@RNabel RNabel commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Fixes 15 type errors that Pyrefly 1.4.0 reports in files that are clean under the pinned 0.24.2, so the Pyrefly upgrade in #5298 starts from a smaller baseline. No runtime behaviour changes.

Issues

None. This is the first of two PRs; the upgrade itself is #5298, stacked on this branch.

Usage

Not applicable: annotations and small restructurings only.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the unit tests and functional tests locally? Visit our Testing Guide for how to run tests
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

Additional Information

What changed (11 files, +25 −20)

  • Local annotations that were narrower than what the code assigns: placements in nccl_reshard_utils.py, mapping in vllm_backend.py, target_missing in nvfp4_pertoken.py, original_values in a diagnostics tool.
  • Names bound in one branch and read in another: idle / active in print_performance_metrics, source_identity in NemoGymDataset, and a function-local import in single_controller_utils/setup.py that moves to the existing module-level import of the same module.
  • _object_payloads is a generator passed to contextlib.closing, so it is annotated Generator instead of Iterator.
  • UnitServer.__init__ accepts threading.Lock | threading.RLock; the storage unit already passes an RLock.
  • Two small ones: an explicit two-way unpack in _gather_tp_gate_up_weight, and int(...) around a .item() used as an index.

No suppression comments or casts are added.

What is left

Pyrefly 1.4.0 goes from 106 errors in 45 files to 91 in 37. The rest need a design decision (override signatures, NestedKey field types, TypedDict shapes, values typed object) and are recorded in the baseline by the upgrade PR.

Latent issues noticed, not changed here

  • TimeoutChecker.mark_iteration raises UnboundLocalError if called before start_iterations(). Every in-repo caller starts first.
  • do_post / _post_local in sglang/utils/http_utils.py raise UnboundLocalError with max_retries <= 0. HttpClient.post validates the value as positive, so it is only reachable by calling the actor method directly.

Testing

Run in a Linux container with the locked environment (uv sync --frozen), CPU only:

  • Pinned Pyrefly 0.24.2 over the whitelist: 0 errors, before and after.
  • Ruff lint, import order and format, and the "clean files must be whitelisted" step: pass.
  • Loss, config, GRPO/PPO and single-controller setup suites: 1483 passed, 95 skipped, same as main.
  • Suites covering the touched files: 533 passed, 5 skipped.
  • No new tests: the changes are annotations and equivalent restructurings. GPU and functional tests were not run, so that box is left unchecked.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

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.

@RNabel

RNabel commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 93db711

@RNabel
RNabel marked this pull request as ready for review November 19, 2026 09:41
Pyrefly 1.4.0 reports 106 errors in files that are clean under the pinned
0.24.2. This fixes the 15 that need no design decision: local annotations
that were narrower than what the code assigns, names bound in one branch
and read in another, and one generator typed as a plain iterator. No
runtime behaviour changes and no suppressions are added. The files stay
clean under 0.24.2.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: Robin Nabel <[email protected]>

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I reviewed all 11 changed files and their directly affected callers, contracts and existing tests. I found no qualifying issues.

Static review only. I did not run tests, lint or Pyrefly, and CI status was unavailable. The reported test results were not independently verified.

Generated by Codex

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

@RNabel
RNabel force-pushed the rnabel/pyrefly-prep-fixes branch from 93db711 to 684dd48 Compare November 19, 2026 09:48
@RNabel

RNabel commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 684dd48

@RNabel RNabel added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 19, 2026

@yuki-97 yuki-97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the type errors that Pyrefly 1.4 reports in the whitelisted files, this is careful and tidy work! It gets these files ready for the Pyrefly upgrade.

Great to see the Pyrefly 1.4.0 before/after error counts, the 0.24.2 result and the unit-suite pass/skip counts posted in the description: the effect of the change is clear to see.

Scope: the PR diff, plus the callers and consumers of each changed annotation, at 684dd48

Checked:

  • Runtime behaviour — unchanged: with annotations stripped, the base and head ASTs differ only in the visible restructurings (idle/active computed inside the branch that prints them in print_performance_metrics, source_identity as an optional in NemoGymDataset, the two-way unpack in _gather_tp_gate_up_weight, int(...) around .item()), and each gives the same result on every path.
  • New annotations — each is true for its assignments and consumers: mapping in vllm_backend.py matches the merged_slice: tuple[slice, ...] | None its consumers declare, placements only ever holds Shard/Replicate, and _object_payloads is a generator whose only caller is contextlib.closing(...), which needs .close(). tq_mooncake_checkpoint.py:945
  • UnitServer's lock widened to threading.Lock | threading.RLock — the right direction: the storage unit passes an RLock because its handlers re-take the same lock, the tests pass a plain Lock, and the lock is only used as with self.lock:; from __future__ import annotations in control.py keeps the union from being evaluated at runtime. control.py:120-124, nixl_storage_unit.py:214
  • Pyrefly results — on 1.4.0 the 15 targeted errors are gone (14 in the changed files plus the RLock argument error at the UnitServer call site in nixl_storage_unit.py) and no new error appears, with no suppression comments or casts added; the pinned 0.24.2 passes in the Lint check job at this head.

LGTM — no remaining findings.

Generated by Claude Code

@yuki-97
yuki-97 enabled auto-merge (squash) November 19, 2026 15:13
@yuki-97
yuki-97 merged commit d259c9a into main Nov 19, 2026
200 of 203 checks passed
@yuki-97
yuki-97 deleted the rnabel/pyrefly-prep-fixes branch November 19, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants