8000 [Set] Raise TypeError if set is called with the wrong number of argum… · pytorch/pytorch@f66a159 · GitHub
[go: up one dir, main page]

Skip to content

Commit f66a159

Browse files
guilhermeleobaspytorchmergebot
authored andcommitted
[Set] Raise TypeError if set is called with the wrong number of arguments (#152990)
Pull Request resolved: #152990 Approved by: https://github.com/anijain2305 ghstack dependencies: #150792, #152987, #152988, #152904, #152901, #152902, #152903, #152905, #152906, #152989, #152907, #152908
1 parent 5a0ca65 commit f66a159

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

test/dynamo_expected_failures/CPython313-test_set-TestSet.test_init

Whitespace-only changes.

torch/_dynamo/variables/builtin.py

+28-18
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,16 @@ def call_set(self, tx: "InstructionTranslator", *args, **kwargs):
16871687
assert not kwargs
16881688
if not args:
16891689
return SetVariable([], mutation_type=ValueMutationNew())
1690-
assert len(args) == 1
1690+
if len(args) != 1:
1691+
raise_observed_exception(
1692+
TypeError,
1693+
tx,
1694+
args=[
1695+
ConstantVariable.create(
1696+
f"set() takes 1 positional argument but {len(args)} were given"
1697+
)
1698+
],
1699+
)
16911700
arg = args[0]
16921701
if isinstance(arg, variables.SetVariable):
16931702
return arg.clone(mutation_type=ValueMutationNew())
@@ -1703,35 +1712,36 @@ def call_set(self, tx: "InstructionTranslator", *args, **kwargs):
17031712
if isinstance(out, SetVariable):
17041713
return out
17051714
return BuiltinVariable(set).call_set(tx, out)
1706-
unimplemented_v2(
1707-
gb_type="failed to construct builtin set()",
1708-
context=f"set(): {args} {kwargs}",
1709-
explanation="Unable to call builtin set() with provided arguments.",
1710-
hints=[
1711-
*graph_break_hints.USER_ERROR,
1712-
*graph_break_hints.SUPPORTABLE,
1713-
],
1715+
raise_observed_exception(
1716+
TypeError,
1717+
tx,
1718+
args=[ConstantVariable.create("failed to construct builtin set()")],
17141719
)
17151720

17161721
def call_frozenset(self, tx: "InstructionTranslator", *args, **kwargs):
17171722
assert not kwargs
17181723
if not args:
17191724
return FrozensetVariable([])
1720-
assert len(args) == 1
1725+
if len(args) != 1:
1726+
raise_observed_exception(
1727+
TypeError,
1728+
tx,
1729+
args=[
1730+
ConstantVariable.create(
1731+
f"frozenset() takes 1 positional argument but {len(args)} were given"
1732+
)
1733+
],
1734+
)
17211735
arg = args[0]
17221736
if isinstance(arg, variables.FrozensetVariable):
17231737
return FrozensetVariable([x.vt for x in arg.set_items])
17241738
elif arg.has_unpack_var_sequence(tx):
17251739
items = arg.unpack_var_sequence(tx)
17261740
return FrozensetVariable(items)
1727-
unimplemented_v2(
1728-
gb_type="failed to construct builtin frozenset()",
1729-
context=f"frozenset(): {args} {kwargs}",
1730-
explanation="Unable to call builtin frozenset() with provided arguments.",
1731-
hints=[
1732-
*graph_break_hints.USER_ERROR,
1733-
*graph_break_hints.SUPPORTABLE,
1734-
],
1741+
raise_observed_exception(
1742+
TypeError,
1743+
tx,
1744+
args=[ConstantVariable.create("failed to construct builtin frozenset()")],
17351745
)
17361746

17371747
def call_zip(self, tx: "InstructionTranslator", *args, **kwargs):

0 commit comments

Comments
 (0)
0