Compare commits

...

2 Commits

Author SHA1 Message Date
6cf5765841 Lint 2025-10-10 16:34:33 -07:00
3be9614164 Correctly error instead of crashing for named tuples 2025-10-10 15:55:33 -07:00
2 changed files with 14 additions and 1 deletions

View File

@ -1069,6 +1069,16 @@ class TestCustomOp(CustomOpTestCaseBase):
del foo
# Define a named tuple for a Point with x and y coordinates
Point = collections.namedtuple("Point", ["x", "y"])
with self.assertRaisesRegex(ValueError, "unsupported type"):
@custom_ops.custom_op(f"{TestCustomOp.test_ns}::foo")
def foo(x: Tensor, y: Point) -> Tensor:
raise NotImplementedError
del foo
def test_supported_schemas(self):
# All of these should already be tested by PyTorch codegen
# (we share the same mechanism), but here's a sanity check.

View File

@ -135,7 +135,10 @@ def infer_schema(
"as it is a ScriptObject. Please manually specify the schema "
"using the `schema=` kwarg with the actual type of the ScriptObject."
)
elif annotation_type.__origin__ is tuple:
elif (
hasattr(annotation_type, "__origin__")
and annotation_type.__origin__ is tuple
):
list_type = tuple_to_list(annotation_type)
example_type_str = "\n\n"
# Only suggest the list type if this type is supported.