Skip to content

Commit fb5be22

Browse files
nandan2003pytorchmergebot
authored andcommitted
Refactor: Remove unnecessary ConstantVariable wrapping in raise_observed_exception (pytorch#168337)
Fixes pytorch#168291 # Summary Removes `ConstantVariable.create` wrapping in `raise_observed_exception` calls within `torch/_dynamo/variables/functions.py`. # Context The `raise_observed_exception` function handles the exception creation internally. Wrapping the error strings in `ConstantVariable` is unnecessary and can be simplified to passing raw strings. # Test Plan - [x] Verified syntax validity via `python3 -m py_compile torch/_dynamo/variables/functions.py` - [ ] CI/CD (Existing tests should pass as this is a refactor of error reporting paths) Pull Request resolved: pytorch#168337 Approved by: https://github.com/williamwen42, https://github.com/guilhermeleobas, https://github.com/cyyever
1 parent bb30341 commit fb5be22

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

torch/_dynamo/variables/functions.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,7 @@ def bind_args_cached(
210210
raise_observed_exception(
211211
TypeError,
212212
tx,
213-
args=[
214-
ConstantVariable.create(
215-
f"Missing required positional argument: {name}"
216-
)
217-
],
213+
args=[f"Missing required positional argument: {name}"],
218214
)
219215

220216
# 2) *args
@@ -226,9 +222,7 @@ def bind_args_cached(
226222
TypeError,
227223
tx,
228224
args=[
229-
ConstantVariable.create(
230-
f"Too many positional arguments: got {len(args)}, expected {len(spec.all_pos_names)}"
231-
)
225+
f"Too many positional arguments: got {len(args)}, expected {len(spec.all_pos_names)}"
232226
],
233227
)
234228

@@ -245,11 +239,7 @@ def bind_args_cached(
245239
raise_observed_exception(
246240
TypeError,
247241
tx,
248-
args=[
249-
ConstantVariable.create(
250-
f"Missing required keyword-only argument: {name}"
251-
)
252-
],
242+
args=[f"Missing required keyword-only argument: {name}"],
253243
)
254244

255245
# 4) **kwargs
@@ -259,9 +249,7 @@ def bind_args_cached(
259249
raise_observed_exception(
260250
TypeError,
261251
tx,
262-
args=[
263-
ConstantVariable.create(f"Unexpected keyword arguments: {list(rem_kw)}")
264-
],
252+
args=[f"Unexpected keyword arguments: {list(rem_kw)}"],
265253
)
266254

267255
return ba
@@ -2994,7 +2982,7 @@ def call_function(
29942982
if len(args) != 1:
29952983
raise_type_error_exc(
29962984
tx,
2997-
f"pytree_get_node_type requires exactly 1 argument, got {len(args)}",
2985+
f"_get_node_type() takes 1 positional argument but {len(args)} were given",
29982986
)
29992987
type_source = None
30002988
if args[0].source:

0 commit comments

Comments
 (0)