Fix type hints for pad functions to use Sequence[tuple[int, int]] - #9027
Fix type hints for pad functions to use Sequence[tuple[int, int]]#9027Harshal875 wants to merge 1 commit into
Conversation
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
📝 WalkthroughWalkthroughPadding type annotations were corrected across array-based transforms and the functional padding API. Estimated code review effort: 1 (Trivial) | ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
monai/transforms/croppad/array.py (1)
121-121: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winComplete 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 andNotImplementedError.monai/transforms/croppad/array.py#L135-L135: add the returnedtorch.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 andValueError.monai/transforms/croppad/array.py#L339-L339: add a docstring covering the returned padding tuple.monai/transforms/croppad/functional.py#L158-L158: document the returnedtorch.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
📒 Files selected for processing (2)
monai/transforms/croppad/array.pymonai/transforms/croppad/functional.py
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
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.