Fix mypy errors: PyTreeSpec inheritance (#160652)

Fixes #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: https://github.com/pytorch/pytorch/pull/160652
Approved by: https://github.com/Skylion007
This commit is contained in:
Rohit Singh Rathaur 2025-08-16 05:14:11 +00:00 committed by PyTorch MergeBot
parent 11b6ceb7b4
commit 114813ca77

View File

@ -994,7 +994,7 @@ class LeafSpecMeta(type(TreeSpec)): # type: ignore[misc]
return _is_pytreespec_instance(instance) and instance.is_leaf()
class LeafSpec(TreeSpec, metaclass=LeafSpecMeta):
class LeafSpec(TreeSpec, metaclass=LeafSpecMeta): # type: ignore[misc,final]
def __new__(cls) -> "LeafSpec":
return optree.treespec_leaf(none_is_leaf=True) # type: ignore[return-value]