Uh oh!
There was an error while loading. Please reload this page.
fx: Fix incorrect return_annotation for tuple types in operator schemas - #189142
Closed
Tejas-Raj01 wants to merge 3 commits into
Closed
fx: Fix incorrect return_annotation for tuple types in operator schemas#189142Tejas-Raj01 wants to merge 3 commits into
Tejas-Raj01 wants to merge 3 commits into
Conversation
When generating Python signatures from C++ schemas, tuple return types were incorrectly parsed as raw Python tuples `(type, ...)` instead of `tuple[type, ...]`. This breaks static type checking and typing inspections downstream. This commit uses `tuple.__class_getitem__` to correctly construct the tuple type annotation dynamically while appeasing strict static type checkers. Fixespytorch#189106
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/189142
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit c1c0de5 with merge base 2b77d2b ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Skylion007
approved these changes
Jul 8, 2026
Skylion007
commented
Jul 8, 2026
Collaborator
Adding regression test if feasible would be ideal. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
cyyever
approved these changes
Jul 9, 2026
Skylion007
approved these changes
Jul 10, 2026
Skylion007
commented
Jul 10, 2026
Collaborator
@pytorchbot merge |
pytorchmergebot
commented
Jul 10, 2026
Collaborator
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
vishalgoyal316 pushed a commit
to vishalgoyal316/pytorch
that referenced
this pull request
Jul 16, 2026
…as (pytorch#189142) Fixespytorch#189106 ### Description Currently, `get_signature_for_torch_op` returns incorrect annotations for operations that return multiple tensors (e.g., `aten.var_mean.default`). Instead of returning standard `tuple[torch.Tensor, torch.Tensor]`, it returns a raw Python tuple of types `(<class 'torch.Tensor'>, <class 'torch.Tensor'>)`, which causes issues with static type checkers and downstream inspection tools. **The Fix:** Used `tuple.__class_getitem__` to correctly construct the tuple type annotation dynamically while appeasing strict static type checkers (like PyRefly/Ruff) that block the `typing.Tuple` syntax. ### Testing - [x] Reproduced the issue locally and verified the output format matches the expected `tuple[...]`. - [x] Passed `lintrunner` locally without any type-ignore hacks. Pull Request resolved: pytorch#189142 Approved by: https://github.com/Skylion007, https://github.com/cyyever
DamJanusz pushed a commit
to DamJanusz/pytorch
that referenced
this pull request
Jul 21, 2026
…as (pytorch#189142) Fixespytorch#189106 ### Description Currently, `get_signature_for_torch_op` returns incorrect annotations for operations that return multiple tensors (e.g., `aten.var_mean.default`). Instead of returning standard `tuple[torch.Tensor, torch.Tensor]`, it returns a raw Python tuple of types `(<class 'torch.Tensor'>, <class 'torch.Tensor'>)`, which causes issues with static type checkers and downstream inspection tools. **The Fix:** Used `tuple.__class_getitem__` to correctly construct the tuple type annotation dynamically while appeasing strict static type checkers (like PyRefly/Ruff) that block the `typing.Tuple` syntax. ### Testing - [x] Reproduced the issue locally and verified the output format matches the expected `tuple[...]`. - [x] Passed `lintrunner` locally without any type-ignore hacks. Pull Request resolved: pytorch#189142 Approved by: https://github.com/Skylion007, https://github.com/cyyever
youlituao pushed a commit
to youlituao/pytorch
that referenced
this pull request
Jul 28, 2026
…as (pytorch#189142) Fixespytorch#189106 ### Description Currently, `get_signature_for_torch_op` returns incorrect annotations for operations that return multiple tensors (e.g., `aten.var_mean.default`). Instead of returning standard `tuple[torch.Tensor, torch.Tensor]`, it returns a raw Python tuple of types `(<class 'torch.Tensor'>, <class 'torch.Tensor'>)`, which causes issues with static type checkers and downstream inspection tools. **The Fix:** Used `tuple.__class_getitem__` to correctly construct the tuple type annotation dynamically while appeasing strict static type checkers (like PyRefly/Ruff) that block the `typing.Tuple` syntax. ### Testing - [x] Reproduced the issue locally and verified the output format matches the expected `tuple[...]`. - [x] Passed `lintrunner` locally without any type-ignore hacks. Pull Request resolved: pytorch#189142 Approved by: https://github.com/Skylion007, https://github.com/cyyever
aws-kingrj pushed a commit
to amazon-contributing/upstream-to-pytorch
that referenced
this pull request
Jul 29, 2026
…as (pytorch#189142) Fixespytorch#189106 ### Description Currently, `get_signature_for_torch_op` returns incorrect annotations for operations that return multiple tensors (e.g., `aten.var_mean.default`). Instead of returning standard `tuple[torch.Tensor, torch.Tensor]`, it returns a raw Python tuple of types `(<class 'torch.Tensor'>, <class 'torch.Tensor'>)`, which causes issues with static type checkers and downstream inspection tools. **The Fix:** Used `tuple.__class_getitem__` to correctly construct the tuple type annotation dynamically while appeasing strict static type checkers (like PyRefly/Ruff) that block the `typing.Tuple` syntax. ### Testing - [x] Reproduced the issue locally and verified the output format matches the expected `tuple[...]`. - [x] Passed `lintrunner` locally without any type-ignore hacks. Pull Request resolved: pytorch#189142 Approved by: https://github.com/Skylion007, https://github.com/cyyever
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes#189106
Description
Currently,
get_signature_for_torch_opreturns incorrect annotations for operations that return multiple tensors (e.g.,aten.var_mean.default). Instead of returning standardtuple[torch.Tensor, torch.Tensor], it returns a raw Python tuple of types(<class 'torch.Tensor'>, <class 'torch.Tensor'>), which causes issues with static type checkers and downstream inspection tools.The Fix:
Used
tuple.__class_getitem__to correctly construct the tuple type annotation dynamically while appeasing strict static type checkers (like PyRefly/Ruff) that block thetyping.Tuplesyntax.Testing
tuple[...].lintrunnerlocally without any type-ignore hacks.