pytorch
764e0ee8 - Improve `Tensor` type hints (#28578)

Commit
5 years ago
Improve `Tensor` type hints (#28578) Summary: I've typed some attributes from https://github.com/pytorch/pytorch/blob/ee920b92c4d52c3481ce4fa1594893fde8ccdd93/torch/csrc/autograd/python_variable.cpp#L490 that were not included in the stubs so that MyPy will be aware of them. I made sure to only add those attributes that are mentioned somewhere in the documentation. If there are attributes mentioned in the documentation that are not meant to be part of the public API (or the opposite), please let me know. I've also made sure that attributes that can't be set are typed as read-only properties. If setting `dtype`, `shape`, `device` or `names` directly is not part of the public API, let me know and I'll make them properties as well. I've also added `__len__`, `__iter__` and `__contains__`, which means MyPy will no longer complain about `len(t)`, `t1 in t2` and `for t1 in t2`. Shameless plug: I have another typing-related PR here that needs review: https://github.com/pytorch/pytorch/pull/27445 Fixes https://github.com/pytorch/pytorch/issues/28457 Pull Request resolved: https://github.com/pytorch/pytorch/pull/28578 Reviewed By: lerks Differential Revision: D18113954 Pulled By: fmassa fbshipit-source-id: 0b69a2966d22054d8d87392f19ec5aa3918773bc
Author
Parents
Loading