Return None correctly from `Tensor.names` (#28659)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28659
Previously, we would return None from `Tensor.names` without bumping the
refcount. This is a bug; the Python API requires the developer to
increment the refcount on new references to None. This is because None
is a singleton object and does not automatically have its reference
count bumped when one uses Py_None (which is a pointer to the actual
None singleton object).
See the following for Python documentation on this:
- https://docs.python.org/3/c-api/none.html#c.Py_RETURN_NONE
- https://docs.python.org/3/extending/extending.html#back-to-the-example
Fixes https://github.com/pytorch/pytorch/issues/28646
Test Plan: - New test.
Differential Revision: D18140593
Pulled By: zou3519
fbshipit-source-id: 302a09021b68229e2e7b1b584b3549b30506bdab