Skip to content

Commit 40fc4ea

Browse files
committed
Fix broken error message format.
1 parent e1e30d9 commit 40fc4ea

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/CreateArgumentsNode.java

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -335,25 +335,49 @@ PException doUncached(Object[] scope_w, Object callable, Arity arity, int co_arg
335335
}
336336

337337
private PException raiseTooManyArguments(Object callable, int co_argcount, int ndefaults, int avail, boolean forgotSelf, int kwonly_given) {
338-
String msg = ndefaults > 0 ? "%s() takes from %d to " : "%s() takes ";
339-
if (kwonly_given == 0) {
340-
throw raise(PythonBuiltinClassType.TypeError, msg + "%d positional argument%s but %d %s given%s",
341-
getName(callable),
342-
co_argcount - ndefaults,
343-
co_argcount,
344-
avail,
345-
avail == 1 ? "was" : "were",
346-
forgotSelf ? ". Did you forget 'self' in the function definition?" : "");
338+
String forgotSelfMsg = forgotSelf ? ". Did you forget 'self' in the function definition?" : "";
339+
if (ndefaults > 0) {
340+
if (kwonly_given == 0) {
341+
throw raise(PythonBuiltinClassType.TypeError, "%s() takes from %d to %d positional argument%s but %d %s given%s",
342+
getName(callable),
343+
co_argcount - ndefaults,
344+
co_argcount,
345+
co_argcount == 1 ? "" : "s",
346+
avail,
347+
avail == 1 ? "was" : "were",
348+
forgotSelfMsg);
349+
} else {
350+
throw raise(PythonBuiltinClassType.TypeError, "%s() takes from %d to %d positional argument%s but %d positional argument%s (and %d keyword-only argument%s) were given%s",
351+
getName(callable),
352+
co_argcount - ndefaults,
353+
co_argcount,
354+
co_argcount == 1 ? "" : "s",
355+
avail,
356+
avail == 1 ? "" : "s",
357+
kwonly_given,
358+
kwonly_given == 1 ? "" : "s",
359+
forgotSelfMsg);
360+
}
347361
} else {
348-
throw raise(PythonBuiltinClassType.TypeError, msg + "%d positional argument%s but %d positional argument%s (and %d keyword-only argument%s) were given%s",
349-
getName(callable),
350-
co_argcount,
351-
co_argcount == 1 ? "" : "s",
352-
avail,
353-
avail == 1 ? "" : "s",
354-
kwonly_given,
355-
kwonly_given == 1 ? "" : "s",
356-
forgotSelf ? ". Did you forget 'self' in the function definition?" : "");
362+
if (kwonly_given == 0) {
363+
throw raise(PythonBuiltinClassType.TypeError, "%s() takes %d positional argument%s but %d %s given%s",
364+
getName(callable),
365+
co_argcount - ndefaults,
366+
co_argcount == 1 ? "" : "s",
367+
avail,
368+
avail == 1 ? "was" : "were",
369+
forgotSelfMsg);
370+
} else {
371+
throw raise(PythonBuiltinClassType.TypeError, "%s() takes %d positional argument%s but %d positional argument%s (and %d keyword-only argument%s) were given%s",
372+
getName(callable),
373+
co_argcount,
374+
co_argcount == 1 ? "" : "s",
375+
avail,
376+
avail == 1 ? "" : "s",
377+
kwonly_given,
378+
kwonly_given == 1 ? "" : "s",
379+
forgotSelfMsg);
380+
}
357381
}
358382
}
359383

0 commit comments

Comments
 (0)