We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
nn.Parameter
Tensor
pyright
Type checking the following script with pyright fails (but not with mypy):
mypy
from typing import assert_type, reveal_type import torch w = torch.randn(3) p = torch.nn.Parameter(w) assert_type(p, torch.nn.Parameter) # ❌ expected "Parameter" but received "Tensor" reveal_type(torch.nn.Parameter.__new__) # (self: type[Self@TensorBase], *args: Unknown, **kwargs: Unknown) -> Tensor
My guess what's happening:
TensorBase
def __new__(self, *args, **kwargs) -> Tensor: ...
torch/_C/__init__.pyi
Parameter.__new__
self: type[Self@TensorBase] -> Tensor
nn.Paramter
It seems the issue can be fixed by simply changing the signature in TensorBase.__new__ to
TensorBase.__new__
def __new__(cls, *args, **kwargs) -> Self
The text was updated successfully, but these errors were encountered:
ccaf03f
Fix: nn.Parameter return type identified as Tensor instead of `nn…
f0de0ab
….Parameter` (pytorch#125106) Fixes pytorch#125105 Pull Request resolved: pytorch#125106 Approved by: https://github.com/ezyang, https://github.com/albanD
738284c
Successfully merging a pull request may close this issue.
🐛 Describe the bug
Type checking the following script with
pyright
fails (but not withmypy
):My guess what's happening:
TensorBase
defines:def __new__(self, *args, **kwargs) -> Tensor: ...
in the stubtorch/_C/__init__.pyi
Parameter.__new__
is untyped. Bothpyright
andmypy
show it'sself: type[Self@TensorBase] -> Tensor
, so reusing the superclasses type.mypy
ignores the discrepancy and treats the result as annn.Paramter
anyway.It seems the issue can be fixed by simply changing the signature in
TensorBase.__new__
toVersions
The text was updated successfully, but these errors were encountered: