[BE] Update .pyi stub template to use Generic TypeAlias (PEP 585) and Union Type (PEP 604)#150728
Closed
XuehaiPan wants to merge 24 commits intogh/XuehaiPan/265/basefrom
Closed
[BE] Update .pyi stub template to use Generic TypeAlias (PEP 585) and Union Type (PEP 604)#150728XuehaiPan wants to merge 24 commits intogh/XuehaiPan/265/basefrom
.pyi stub template to use Generic TypeAlias (PEP 585) and Union Type (PEP 604)#150728XuehaiPan wants to merge 24 commits intogh/XuehaiPan/265/basefrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/150728
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit 0bf4d53 with merge base e2ce17c ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Apr 5, 2025
Contributor
There was a problem hiding this comment.
Copilot reviewed 3 out of 6 changed files in this pull request and generated no comments.
Files not reviewed (3)
- torch/_C/_VariableFunctions.pyi.in: Language not supported
- torch/_C/_nn.pyi.in: Language not supported
- torch/_C/return_types.pyi.in: Language not supported
XuehaiPan
added a commit
to XuehaiPan/pytorch
that referenced
this pull request
May 2, 2025
…nd Union Type (PEP 604) ghstack-source-id: 1b3c032 Pull Request resolved: pytorch#150728
XuehaiPan
added a commit
to XuehaiPan/pytorch
that referenced
this pull request
May 10, 2025
…nd Union Type (PEP 604) ghstack-source-id: d3c3cda Pull Request resolved: pytorch#150728
XuehaiPan
added a commit
to XuehaiPan/pytorch
that referenced
this pull request
May 14, 2025
…nd Union Type (PEP 604) ghstack-source-id: 64ee282 Pull Request resolved: pytorch#150728
aorenste
approved these changes
May 14, 2025
XuehaiPan
added a commit
to XuehaiPan/pytorch
that referenced
this pull request
May 14, 2025
…nd Union Type (PEP 604) ghstack-source-id: bb1495f Pull Request resolved: pytorch#150728
Collaborator
Author
|
@pytorchbot merge |
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 |
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 free
to 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.
#129001 (comment) is the motivation for the whole stack of PRs. In
torch/__init__.py,torch._C.Typeshadowsfrom typing import Type, and there is no type stub fortorch._C.Typeintorch/_C/__init__.pyi. So we need to usefrom typing import Type as _Type. After enabling Generic TypeAlias (PEP 585) in the.pyitype stub files, we can usetypeinstead oftyping.Typeorfrom typing import Type as _Type.typing.List[T] -> list[T],typing.Dict[KT, VT] -> dict[KT, VT],typing.Type[T] -> type[T].Union[X, Y] -> X | Y,Optional[X] -> X | None,Optional[Union[X, Y]] -> X | Y | None.Note that in
.pyistub files, we do not needfrom __future__ import annotations. So this PR does not violate issue #117449:Stack from ghstack (oldest at bottom):
lintrunneron generated.pyistub files #150732.pyistub files #150731gen_pyiare properly formatted #150730torch/utils/data/datapipes/gen_pyi.pywithtorchgen#150626__all__totorch/nn/functional.pyiandtorch/return_types.pyi#150729.pyistub template to use Generic TypeAlias (PEP 585) and Union Type (PEP 604) #150728gen_pyi.pyto use Generic TypeAlias (PEP 585) and Union Type (PEP 604) #150727torchgen.utils.FileManagerto acceptpathlib.Path#150726cc @ezyang @malfet @xuzhao9 @gramster @bhosmer @bdhirsh @kadeng