Skip to content

Fix type hints for pad functions to use Sequence[tuple[int, int]] - #9027

Open
Harshal875 wants to merge 1 commit into
Project-MONAI:devfrom
Harshal875:dev
Open

Fix type hints for pad functions to use Sequence[tuple[int, int]]#9027
Harshal875 wants to merge 1 commit into
Project-MONAI:devfrom
Harshal875:dev

Conversation

@Harshal875

@Harshal875 Harshal875 commented Jul 28, 2026

Copy link
Copy Markdown

The to_pad parameter and compute_pad_width return types used tuple[tuple[int, int]] which restricts to a single inner tuple. Changed to_pad to Sequence[tuple[int, int]] and compute_pad_width returns to tuple[tuple[int, int], ...] to correctly allow padding tuples for every dimension. Fixes #9026

Fixes # .

Description

A few sentences describing the changes proposed in this pull request.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

The to_pad parameter and compute_pad_width return types used tuple[tuple[int, int]] which restricts to a single inner tuple. Changed to_pad to Sequence[tuple[int, int]] and compute_pad_width returns to tuple[tuple[int, int], ...] to correctly allow padding tuples for every dimension. Fixes Project-MONAI#9026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Padding type annotations were corrected across array-based transforms and the functional padding API. to_pad now accepts a Sequence of (low, high) pairs, and compute_pad_width methods describe variable-length per-dimension results. Runtime padding behavior is unchanged.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: widening pad type hints to Sequence tuples.
Description check ✅ Passed The description includes the change summary, linked issue, and a filled type-of-change item, though it is a bit noisy.
Linked Issues check ✅ Passed The PR updates pad_func to accept Sequence[tuple[int, int]], matching the linked issue and keeping related pad typing consistent.
Out of Scope Changes check ✅ Passed The extra Pad type-hint updates are closely related API consistency changes, not unrelated scope creep.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
monai/transforms/croppad/array.py (1)

121-121: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Complete the Google-style documentation for the modified padding APIs.

The annotations correctly widen the contract, but the corresponding method docstrings do not fully document return values and raised exceptions.

  • monai/transforms/croppad/array.py#L121-L121: document the returned per-dimension padding tuple and NotImplementedError.
  • monai/transforms/croppad/array.py#L135-L135: add the returned torch.Tensor.
  • monai/transforms/croppad/array.py#L221-L221: document the returned padding tuple.
  • monai/transforms/croppad/array.py#L276-L276: add a docstring covering the return value and ValueError.
  • monai/transforms/croppad/array.py#L339-L339: add a docstring covering the returned padding tuple.
  • monai/transforms/croppad/functional.py#L158-L158: document the returned torch.Tensor.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@monai/transforms/croppad/array.py` at line 121, Complete the Google-style
docstrings for the padding APIs: in monai/transforms/croppad/array.py at lines
121-121, document compute_pad_width’s per-dimension padding tuple return and
NotImplementedError; at 135-135 document the returned torch.Tensor; at 221-221
document the returned padding tuple; at 276-276 add return and ValueError
documentation; and at 339-339 document the returned padding tuple. In
monai/transforms/croppad/functional.py at lines 158-158, document the returned
torch.Tensor, preserving each method’s existing behavior.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@monai/transforms/croppad/array.py`:
- Line 121: Complete the Google-style docstrings for the padding APIs: in
monai/transforms/croppad/array.py at lines 121-121, document compute_pad_width’s
per-dimension padding tuple return and NotImplementedError; at 135-135 document
the returned torch.Tensor; at 221-221 document the returned padding tuple; at
276-276 add return and ValueError documentation; and at 339-339 document the
returned padding tuple. In monai/transforms/croppad/functional.py at lines
158-158, document the returned torch.Tensor, preserving each method’s existing
behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 53a5286b-8f82-43d6-a702-5eb391b9cc4c

📥 Commits

Reviewing files that changed from the base of the PR and between 3ee058b and 4f8ab7c.

📒 Files selected for processing (2)
  • monai/transforms/croppad/array.py
  • monai/transforms/croppad/functional.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect type hint in pad_func

1 participant