Skip to content

Commit cb7ea11

Browse files
Add prefix "format argument: " for a single argument.
1 parent 4e5538b commit cb7ea11

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

Lib/test/test_format.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -335,23 +335,23 @@ def test_common_format(self):
335335
test_exc_common('%.*r', (-2**1000, 1), OverflowError,
336336
"format argument 1: too big for precision")
337337
test_exc_common('%d', '1', TypeError,
338-
"%d requires a real number, not str")
338+
"format argument: %d requires a real number, not str")
339339
test_exc_common('%d', b'1', TypeError,
340-
"%d requires a real number, not bytes")
340+
"format argument: %d requires a real number, not bytes")
341341
test_exc_common('%d', ('1',), TypeError,
342342
"format argument 1: %d requires a real number, not str")
343343
test_exc_common('%x', '1', TypeError,
344-
"%x requires an integer, not str")
344+
"format argument: %x requires an integer, not str")
345345
test_exc_common('%x', 3.14, TypeError,
346-
"%x requires an integer, not float")
346+
"format argument: %x requires an integer, not float")
347347
test_exc_common('%x', ('1',), TypeError,
348348
"format argument 1: %x requires an integer, not str")
349349
test_exc_common('%i', '1', TypeError,
350-
"%i requires a real number, not str")
350+
"format argument: %i requires a real number, not str")
351351
test_exc_common('%i', b'1', TypeError,
352-
"%i requires a real number, not bytes")
352+
"format argument: %i requires a real number, not bytes")
353353
test_exc_common('%g', '1', TypeError,
354-
"%g requires a real number, not str")
354+
"format argument: %g requires a real number, not str")
355355
test_exc_common('%g', ('1',), TypeError,
356356
"format argument 1: %g requires a real number, not str")
357357

@@ -395,29 +395,30 @@ def test_str_format(self):
395395
"format argument 'x': %x requires an integer, not str")
396396
test_exc('%(x)g', {'x': '1'}, TypeError,
397397
"format argument 'x': %g requires a real number, not str")
398-
test_exc('%c', -1, OverflowError, "%c argument not in range(0x110000)")
398+
test_exc('%c', -1, OverflowError,
399+
"format argument: %c argument not in range(0x110000)")
399400
test_exc('%c', (-1,), OverflowError,
400401
"format argument 1: %c argument not in range(0x110000)")
401402
test_exc('%(x)c', {'x': -1}, OverflowError,
402403
"format argument 'x': %c argument not in range(0x110000)")
403404
test_exc('%c', sys.maxunicode+1, OverflowError,
404-
"%c argument not in range(0x110000)")
405+
"format argument: %c argument not in range(0x110000)")
405406
test_exc('%c', 2**128, OverflowError,
406-
"%c argument not in range(0x110000)")
407+
"format argument: %c argument not in range(0x110000)")
407408
test_exc('%c', 3.14, TypeError,
408-
"%c requires an integer or a unicode character, not float")
409+
"format argument: %c requires an integer or a unicode character, not float")
409410
test_exc('%c', (3.14,), TypeError,
410411
"format argument 1: %c requires an integer or a unicode character, not float")
411412
test_exc('%(x)c', {'x': 3.14}, TypeError,
412413
"format argument 'x': %c requires an integer or a unicode character, not float")
413414
test_exc('%c', 'ab', TypeError,
414-
"%c requires an integer or a unicode character, not a string of length 2")
415+
"format argument: %c requires an integer or a unicode character, not a string of length 2")
415416
test_exc('%c', ('ab',), TypeError,
416417
"format argument 1: %c requires an integer or a unicode character, not a string of length 2")
417418
test_exc('%(x)c', {'x': 'ab'}, TypeError,
418419
"format argument 'x': %c requires an integer or a unicode character, not a string of length 2")
419420
test_exc('%c', b'x', TypeError,
420-
"%c requires an integer or a unicode character, not bytes")
421+
"format argument: %c requires an integer or a unicode character, not bytes")
421422

422423
if maxsize == 2**31-1:
423424
# crashes 2.2.1 and earlier:
@@ -498,37 +499,37 @@ def __bytes__(self):
498499
test_exc(b'%(x)g', {b'x': '1'}, TypeError,
499500
"format argument b'x': %g requires a real number, not str")
500501
test_exc(b"%c", -1, OverflowError,
501-
"%c argument not in range(256)")
502+
"format argument: %c argument not in range(256)")
502503
test_exc(b"%c", (-1,), OverflowError,
503504
"format argument 1: %c argument not in range(256)")
504505
test_exc(b"%(x)c", {b'x': -1}, OverflowError,
505506
"format argument b'x': %c argument not in range(256)")
506507
test_exc(b"%c", 256, OverflowError,
507-
"%c argument not in range(256)")
508+
"format argument: %c argument not in range(256)")
508509
test_exc(b"%c", 2**128, OverflowError,
509-
"%c argument not in range(256)")
510+
"format argument: %c argument not in range(256)")
510511
test_exc(b"%c", b"Za", TypeError,
511-
"%c requires an integer in range(256) or a single byte, not a bytes object of length 2")
512+
"format argument: %c requires an integer in range(256) or a single byte, not a bytes object of length 2")
512513
test_exc(b"%c", (b"Za",), TypeError,
513514
"format argument 1: %c requires an integer in range(256) or a single byte, not a bytes object of length 2")
514515
test_exc(b"%(x)c", {b'x': b"Za"}, TypeError,
515516
"format argument b'x': %c requires an integer in range(256) or a single byte, not a bytes object of length 2")
516517
test_exc(b"%c", bytearray(b"Za"), TypeError,
517-
"%c requires an integer in range(256) or a single byte, not a bytearray object of length 2")
518+
"format argument: %c requires an integer in range(256) or a single byte, not a bytearray object of length 2")
518519
test_exc(b"%c", (bytearray(b"Za"),), TypeError,
519520
"format argument 1: %c requires an integer in range(256) or a single byte, not a bytearray object of length 2")
520521
test_exc(b"%(x)c", {b'x': bytearray(b"Za")}, TypeError,
521522
"format argument b'x': %c requires an integer in range(256) or a single byte, not a bytearray object of length 2")
522523
test_exc(b"%c", "Y", TypeError,
523-
"%c requires an integer in range(256) or a single byte, not str")
524+
"format argument: %c requires an integer in range(256) or a single byte, not str")
524525
test_exc(b"%c", 3.14, TypeError,
525-
"%c requires an integer in range(256) or a single byte, not float")
526+
"format argument: %c requires an integer in range(256) or a single byte, not float")
526527
test_exc(b"%c", (3.14,), TypeError,
527528
"format argument 1: %c requires an integer in range(256) or a single byte, not float")
528529
test_exc(b"%(x)c", {b'x': 3.14}, TypeError,
529530
"format argument b'x': %c requires an integer in range(256) or a single byte, not float")
530531
test_exc(b"%b", "Xc", TypeError,
531-
"%b requires a bytes-like object, "
532+
"format argument: %b requires a bytes-like object, "
532533
"or an object that implements __bytes__, not str")
533534
test_exc(b"%b", ("Xc",), TypeError,
534535
"format argument 1: %b requires a bytes-like object, "
@@ -537,7 +538,7 @@ def __bytes__(self):
537538
"format argument b'x': %b requires a bytes-like object, "
538539
"or an object that implements __bytes__, not str")
539540
test_exc(b"%s", "Wd", TypeError,
540-
"%b requires a bytes-like object, "
541+
"format argument: %b requires a bytes-like object, "
541542
"or an object that implements __bytes__, not str")
542543

543544
if maxsize == 2**31-1:

Objects/bytesobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ PyBytes_FromFormat(const char *format, ...)
414414
argidx, __VA_ARGS__); \
415415
} \
416416
else { \
417-
PyErr_Format((EXC), FMT, __VA_ARGS__); \
417+
PyErr_Format((EXC), "format argument: " FMT, __VA_ARGS__); \
418418
} \
419419
} while (0)
420420

Objects/unicode_format.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct unicode_format_arg_t {
8787
ctx->argidx, __VA_ARGS__); \
8888
} \
8989
else { \
90-
PyErr_Format((EXC), FMT, __VA_ARGS__); \
90+
PyErr_Format((EXC), "format argument: " FMT, __VA_ARGS__); \
9191
} \
9292
} while (0)
9393

0 commit comments

Comments
 (0)