-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Incorrect return type hint for torch.nonzero #51434
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
Comments
Thanks for the report @nlgranger.
That isn't quite right, returning unions like that will just cause problems further down the line where mypy doesn't know if it's a tensor or a tuple. Instead it should have an extra overload ( |
Mypy seems confused, it doesn't warn:
gives:
|
The overloads are a little tricky here. It's important that the overloads are such that it's unambiguous what `torch.nonzero(x)` will resolve to - so just specify defaults for one of the overloads. Also, `out` is left out of the second overload because a non-None value for `out` is not valid in combination with `as_tuple=True`. Closes pytorchgh-51434
Summary: The overloads are a little tricky here. It's important that the overloads are such that it's unambiguous what `torch.nonzero(x)` will resolve to - so just specify defaults for one of the overloads. Also, `out` is left out of the second overload because a non-None value for `out` is not valid in combination with `as_tuple=True`. Closes pytorchgh-51434 Pull Request resolved: pytorch#51635 Reviewed By: zhangguanheng66 Differential Revision: D26279203 Pulled By: walterddr fbshipit-source-id: 8459c04fc9fbf7fc5f31b3f631aaac2f98b17ea6
Uh oh!
There was an error while loading. Please reload this page.
🐛 Bug
The type hint for torch.nonzero is incomplete, it only specifies Tensor.
To Reproduce
Steps to reproduce the behavior:
as_tuple=True
Expected behavior
There is no warning
Additional context
pytorch/tools/pyi/gen_pyi.py
Line 326 in 9dfbfe9
And Tensor.nonzero might need to be updated too I suppose.
cc @mruberry @rgommers @heitorschueroff @ezyang @malfet @xuzhao9 @gramster
The text was updated successfully, but these errors were encountered: