Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/test_custom_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,15 @@ def blah8(x, *, y=1):
def blah9(x, *, y):
pass

def test_infer_schema_no_return(self):
with self.assertRaisesRegex(
ValueError, "No return type annotation was provided. Please add one."
):

@torch.library.custom_op("mylib::foo", mutates_args={})
def foo(x: torch.Tensor, y: int):
return x * y

def test_infer_schema_supported(self):
def a(x: Tensor) -> Tensor:
return torch.empty([])
Expand Down
3 changes: 3 additions & 0 deletions torch/_library/infer_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def parse_return(annotation, error_fn):
if annotation is None:
return "()"

if annotation is inspect.Parameter.empty:
error_fn("No return type annotation was provided. Please add one.")

origin = typing.get_origin(annotation)
if origin is not tuple:
if annotation not in SUPPORTED_RETURN_TYPES.keys():
Expand Down