mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Disambiguate error message for working with not fully refined tuple types (#55745)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/55745 Test Plan: Imported from OSS Reviewed By: gmagogsfm Differential Revision: D27698691 Pulled By: tugsbayasgalan fbshipit-source-id: 7855042d37290f19d53adfc0b4da606430501663
This commit is contained in:
committed by
Facebook GitHub Bot
parent
facbcec298
commit
b80c6f863f
@ -12652,6 +12652,14 @@ dedent """
|
||||
return e
|
||||
self.checkScript(foo, (torch.rand(3), torch.rand(3)))
|
||||
|
||||
def test_tuple_error_msg(self):
|
||||
def fn(t: Any):
|
||||
if isinstance(t, tuple):
|
||||
a, b = t
|
||||
return a + b
|
||||
with self.assertRaisesRegexWithHighlight(RuntimeError, "Provided tuple is not fully defined/refined", "t"):
|
||||
s = torch.jit.script(fn)
|
||||
|
||||
def test_augmented_assign(self):
|
||||
def foo(a, b):
|
||||
a += b
|
||||
|
@ -238,6 +238,9 @@ std::vector<std::shared_ptr<SugaredValue>> SimpleValue::asTuple(
|
||||
Node* unpack =
|
||||
graph->insertNode(graph->createListUnpack(value_, *size_hint));
|
||||
return fmap(unpack->outputs(), make_simple_value);
|
||||
} else if (value_->type()->kind() == TypeKind::AnyTupleType) {
|
||||
throw ErrorReport(loc)
|
||||
<< "Provided tuple is not fully defined/refined including its element types, please provide a value of type like Tuple[int, int]";
|
||||
}
|
||||
throw ErrorReport(loc) << value_->type()->repr_str()
|
||||
<< " cannot be used as a tuple";
|
||||
|
Reference in New Issue
Block a user