-
Notifications
You must be signed in to change notification settings - Fork 24.2k
[BE] Update .pyi
stub template to use Generic TypeAlias (PEP 585) and Union Type (PEP 604)
#150728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
…nd Union Type (PEP 604) ghstack-source-id: 89c7367 Pull Request resolved: pytorch#150728
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
…nd Union Type (PEP 604) ghstack-source-id: a4b50c0 Pull Request resolved: pytorch#150728
…nd Union Type (PEP 604) ghstack-source-id: a4b50c0 Pull Request resolved: pytorch#150728
…nd Union Type (PEP 604) ghstack-source-id: 22538ec Pull Request resolved: pytorch#150728
…nd Union Type (PEP 604) ghstack-source-id: b962350 Pull Request resolved: pytorch#150728
…nd Union Type (PEP 604) ghstack-source-id: 3755b3a Pull Request resolved: pytorch#150728
…nd Union Type (PEP 604) ghstack-source-id: 96e526c Pull Request resolved: pytorch#150728
…nd Union Type (PEP 604) ghstack-source-id: 2a81956 Pull Request resolved: pytorch#150728
…nd Union Type (PEP 604) ghstack-source-id: 1b3c032 Pull Request resolved: pytorch#150728
…nd Union Type (PEP 604) ghstack-source-id: d3c3cda Pull Request resolved: pytorch#150728
…nd Union Type (PEP 604) ghstack-source-id: d3c3cda Pull Request resolved: pytorch#150728
…nd Union Type (PEP 604) ghstack-source-id: 64ee282 Pull Request resolved: pytorch#150728
…nd Union Type (PEP 604) ghstack-source-id: bb1495f Pull Request resolved: pytorch#150728
…nd Union Type (PEP 604) ghstack-source-id: bb1495f Pull Request resolved: pytorch#150728
@pytorchbot merge |
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 |
#129001 (comment) is the motivation for the whole stack of PRs. In
torch/__init__.py
,torch._C.Type
shadowsfrom typing import Type
, and there is no type stub fortorch._C.Type
intorch/_C/__init__.pyi
. So we need to usefrom typing import Type as _Type
. After enabling Generic TypeAlias (PEP 585) in the.pyi
type stub files, we can usetype
instead oftyping.Type
orfrom 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
.pyi
stub files, we do not needfrom __future__ import annotations
. So this PR does not violate issue #117449:Stack from ghstack (oldest at bottom):
lintrunner
on generated.pyi
stub files #150732.pyi
stub files #150731gen_pyi
are properly formatted #150730torch/utils/data/datapipes/gen_pyi.py
withtorchgen
#150626__all__
totorch/nn/functional.pyi
andtorch/return_types.pyi
#150729.pyi
stub template to use Generic TypeAlias (PEP 585) and Union Type (PEP 604) #150728gen_pyi.py
to use Generic TypeAlias (PEP 585) and Union Type (PEP 604) #150727torchgen.utils.FileManager
to acceptpathlib.Path
#150726cc @ezyang @malfet @xuzhao9 @gramster @bhosmer @bdhirsh @kadeng