Fix mypy errors: PyTreeSpec inheritance#160652
Fix mypy errors: PyTreeSpec inheritance#160652RohitRathore1 wants to merge 3 commits intopytorch:mainfrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/160652
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit 7d12076 with merge base cd8d8c1 ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label "topic: not user facing" |
|
|
||
|
|
||
| class LeafSpec(TreeSpec, metaclass=LeafSpecMeta): | ||
| class LeafSpec(TreeSpec, metaclass=LeafSpecMeta): # type: ignore[misc,final] |
There was a problem hiding this comment.
Why is the parent class final? Seems like a typing error upstream?
There was a problem hiding this comment.
You're right. The PyTreeSpec class from the optree library is marked as @final in their type stubs, but PyTorch's LeafSpec has been inheriting from it successfully at runtime but this inheritance is working fine at runtime, the type ignore seems like the most pragmatic short-term fix while we could potentially discuss about the @final annotation.
There was a problem hiding this comment.
The LeafSpec class in _cxx_pytree.py is used to align the public APIs with _pytree.py. It is not intended to be used. Now, both Python and C++ pytree are using .is_leaf() method:
# previous code
isinsatnce(spec, LeafSpec)
# current
spec.is_leaf()|
The CI failure is due to |
|
@pytorchbot merge -f "MYPYSTRICT is only run on changed file. lint will be green on trunk" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…unner-mypy` (#160806) Like `MYPY`, linter `MYPYSTRICT` will need `--all-files` too. See also: - #160652 (comment) Pull Request resolved: #160806 Approved by: https://github.com/seemethere
Fixes pytorch#160650. I added type ignore comment to `LeafSpec` class inheritance in `torch/utils/_cxx_pytree.py` to handle `PyTreeSpec` being marked as final in optree's type stubs. Pull Request resolved: pytorch#160652 Approved by: https://github.com/Skylion007
…unner-mypy` (pytorch#160806) Like `MYPY`, linter `MYPYSTRICT` will need `--all-files` too. See also: - pytorch#160652 (comment) Pull Request resolved: pytorch#160806 Approved by: https://github.com/seemethere
Fixes pytorch#160650. I added type ignore comment to `LeafSpec` class inheritance in `torch/utils/_cxx_pytree.py` to handle `PyTreeSpec` being marked as final in optree's type stubs. Pull Request resolved: pytorch#160652 Approved by: https://github.com/Skylion007
…unner-mypy` (pytorch#160806) Like `MYPY`, linter `MYPYSTRICT` will need `--all-files` too. See also: - pytorch#160652 (comment) Pull Request resolved: pytorch#160806 Approved by: https://github.com/seemethere
Fixes #160650.
I added type ignore comment to
LeafSpecclass inheritance intorch/utils/_cxx_pytree.pyto handlePyTreeSpecbeing marked as final in optree's type stubs.cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @chenyang78 @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben