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
Improve Tensor
type hints
#28578
Improve Tensor
type hints
#28578
Conversation
- Add some missing attributes - Add some missing methods - Type read-only attributes as properties Fixes pytorch#28457
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fmassa has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect that python/mypy#4146 could cause an issue with the layout property.
python/mypy#4146 is causing problems it seems. I'll have a look. Edit: Should be good now. |
Workaround for python/mypy#4146
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fmassa has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fmassa has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
I've typed some attributes from
pytorch/torch/csrc/autograd/python_variable.cpp
Line 490 in ee920b9
dtype
,shape
,device
ornames
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 aboutlen(t)
,t1 in t2
andfor t1 in t2
.Shameless plug: I have another typing-related PR here that needs review: #27445
Fixes #28457