mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Forbid subclassing _TensorBase directly (#125558)
As per title. This ensures that all the places where we assume the method defined in _tensor.py do exist. BC-Breaking: This is bc-breaking as the user cannot subclass this private class anymore. You should replace any use of _TensorBase to Tensor. Pull Request resolved: https://github.com/pytorch/pytorch/pull/125558 Approved by: https://github.com/ezyang
This commit is contained in:
@ -769,7 +769,7 @@ $1: f32[] = torch._ops.my_lib.weird.default(['None', '$0'])""",
|
||||
# test all sequence types are permissible returns
|
||||
for list_type in (list, tuple):
|
||||
|
||||
class A(torch._C.TensorBase):
|
||||
class A(torch.Tensor):
|
||||
@staticmethod
|
||||
def __new__(cls, elem):
|
||||
return torch.Tensor._make_subclass(cls, elem, elem.requires_grad)
|
||||
@ -789,7 +789,7 @@ $1: f32[] = torch._ops.my_lib.weird.default(['None', '$0'])""",
|
||||
|
||||
def test_invalid_ret(self) -> None:
|
||||
# test invalid return gets reasonable error message
|
||||
class A(torch._C.TensorBase):
|
||||
class A(torch.Tensor):
|
||||
@staticmethod
|
||||
def __new__(cls, elem):
|
||||
return torch.Tensor._make_subclass(cls, elem, elem.requires_grad)
|
||||
|
Reference in New Issue
Block a user