after updating to pytorch 1.6 mypy does not recognise the tensor attributes ndim, nonzero and T

🐛 Bug

after updating to pytorch 1.6 mypy does not recognise the tensor attributes ndim, nonzero and T.

The mypy errors are:
error: “Tensor” has no attribute “T”
error: “Tensor” has no attribute “ndim”
error: “Tensor” has no attribute “nonzero”

Expected behavior

No errors

Environment

  • PyTorch 1.6
    before updating to pytorch 1.6. everything was working fine.

cc @ezyang @gchanan @zou3519 @malfet @rgommers

1 possible answer(s) on “after updating to pytorch 1.6 mypy does not recognise the tensor attributes ndim, nonzero and T

  1. The nonzero omission may have been intentional because Tensor.nonzero() is deprecated. Weirdly enough Tensor.nonzero(as_tuple=...) is not deprecated, but that may be an error in how the deprecation was implemented – I assume the whole method will be removed.

    Other deprecated functions and methods still have annotations though, and in gen_pyi.py there’s a TODO: maybe we shouldn't genrate type hits for deprecated functions note, but that has drawbacks as well. So I opened a PR to add back the annotation.