Skip to content

Commit 35c6097

Browse files
committed
Remove callable name from TypeError messages with invalid values after * and **
1 parent 11f074b commit 35c6097

File tree

4 files changed

+23
-34
lines changed

4 files changed

+23
-34
lines changed

Lib/test/pickletester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,7 @@ def test_bad_newobj_ex_args(self):
18721872
with self.assertRaises(TypeError) as cm:
18731873
self.dumps(obj, proto)
18741874
self.assertEqual(str(cm.exception),
1875-
'functools.partial() argument after ** must be a mapping, not list')
1875+
'Value after ** must be a mapping, not list')
18761876
self.assertEqual(cm.exception.__notes__, [
18771877
'when serializing test.pickletester.REX object'])
18781878
else:

Lib/test/test_extcall.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
>>> g(*Nothing())
138138
Traceback (most recent call last):
139139
...
140-
TypeError: test.test_extcall.g() argument after * must be an iterable, not Nothing
140+
TypeError: Value after * must be an iterable, not Nothing
141141
142142
>>> class Nothing:
143143
... def __len__(self): return 5
@@ -146,7 +146,7 @@
146146
>>> g(*Nothing())
147147
Traceback (most recent call last):
148148
...
149-
TypeError: test.test_extcall.g() argument after * must be an iterable, not Nothing
149+
TypeError: Value after * must be an iterable, not Nothing
150150
151151
>>> class Nothing():
152152
... def __len__(self): return 5
@@ -266,7 +266,7 @@
266266
>>> h(*h)
267267
Traceback (most recent call last):
268268
...
269-
TypeError: test.test_extcall.h() argument after * must be an iterable, not function
269+
TypeError: Value after * must be an iterable, not function
270270
271271
>>> h(1, *h)
272272
Traceback (most recent call last):
@@ -281,54 +281,54 @@
281281
>>> dir(*h)
282282
Traceback (most recent call last):
283283
...
284-
TypeError: dir() argument after * must be an iterable, not function
284+
TypeError: Value after * must be an iterable, not function
285285
286286
>>> nothing = None
287287
>>> nothing(*h)
288288
Traceback (most recent call last):
289289
...
290-
TypeError: None argument after * must be an iterable, \
290+
TypeError: Value after * must be an iterable, \
291291
not function
292292
293293
>>> h(**h)
294294
Traceback (most recent call last):
295295
...
296-
TypeError: test.test_extcall.h() argument after ** must be a mapping, not function
296+
TypeError: Value after ** must be a mapping, not function
297297
298298
>>> h(**[])
299299
Traceback (most recent call last):
300300
...
301-
TypeError: test.test_extcall.h() argument after ** must be a mapping, not list
301+
TypeError: Value after ** must be a mapping, not list
302302
303303
>>> h(a=1, **h)
304304
Traceback (most recent call last):
305305
...
306-
TypeError: test.test_extcall.h() argument after ** must be a mapping, not function
306+
TypeError: Value after ** must be a mapping, not function
307307
308308
>>> h(a=1, **[])
309309
Traceback (most recent call last):
310310
...
311-
TypeError: test.test_extcall.h() argument after ** must be a mapping, not list
311+
TypeError: Value after ** must be a mapping, not list
312312
313313
>>> h(**{'a': 1}, **h)
314314
Traceback (most recent call last):
315315
...
316-
TypeError: test.test_extcall.h() argument after ** must be a mapping, not function
316+
TypeError: Value after ** must be a mapping, not function
317317
318318
>>> h(**{'a': 1}, **[])
319319
Traceback (most recent call last):
320320
...
321-
TypeError: test.test_extcall.h() argument after ** must be a mapping, not list
321+
TypeError: Value after ** must be a mapping, not list
322322
323323
>>> dir(**h)
324324
Traceback (most recent call last):
325325
...
326-
TypeError: dir() argument after ** must be a mapping, not function
326+
TypeError: Value after ** must be a mapping, not function
327327
328328
>>> nothing(**h)
329329
Traceback (most recent call last):
330330
...
331-
TypeError: None argument after ** must be a mapping, \
331+
TypeError: Value after ** must be a mapping, \
332332
not function
333333
334334
>>> dir(b=1, **{'b': 1})
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Errors when calling functions with invalid values after * and ** now do not
2+
include the function name.

Python/ceval.c

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3264,17 +3264,9 @@ int
32643264
_Py_Check_ArgsIterable(PyThreadState *tstate, PyObject *func, PyObject *args)
32653265
{
32663266
if (Py_TYPE(args)->tp_iter == NULL && !PySequence_Check(args)) {
3267-
/* _Py_Check_ArgsIterable() may be called with a live exception:
3268-
* clear it to prevent calling _PyObject_FunctionStr() with an
3269-
* exception set. */
3270-
_PyErr_Clear(tstate);
3271-
PyObject *funcstr = _PyObject_FunctionStr(func);
3272-
if (funcstr != NULL) {
3273-
_PyErr_Format(tstate, PyExc_TypeError,
3274-
"%U argument after * must be an iterable, not %.200s",
3275-
funcstr, Py_TYPE(args)->tp_name);
3276-
Py_DECREF(funcstr);
3277-
}
3267+
_PyErr_Format(tstate, PyExc_TypeError,
3268+
"Value after * must be an iterable, not %.200s",
3269+
Py_TYPE(args)->tp_name);
32783270
return -1;
32793271
}
32803272
return 0;
@@ -3290,15 +3282,10 @@ _PyEval_FormatKwargsError(PyThreadState *tstate, PyObject *func, PyObject *kwarg
32903282
* is not a mapping.
32913283
*/
32923284
if (_PyErr_ExceptionMatches(tstate, PyExc_AttributeError)) {
3293-
_PyErr_Clear(tstate);
3294-
PyObject *funcstr = _PyObject_FunctionStr(func);
3295-
if (funcstr != NULL) {
3296-
_PyErr_Format(
3297-
tstate, PyExc_TypeError,
3298-
"%U argument after ** must be a mapping, not %.200s",
3299-
funcstr, Py_TYPE(kwargs)->tp_name);
3300-
Py_DECREF(funcstr);
3301-
}
3285+
_PyErr_Format(
3286+
tstate, PyExc_TypeError,
3287+
"Value after ** must be a mapping, not %.200s",
3288+
Py_TYPE(kwargs)->tp_name);
33023289
}
33033290
else if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
33043291
PyObject *exc = _PyErr_GetRaisedException(tstate);

0 commit comments

Comments
 (0)