Skip to content

Commit 4e5538b

Browse files
Merge branch 'str-format-errors' of github.com:serhiy-storchaka/cpython into str-format-errors
2 parents 0e43000 + c015d6a commit 4e5538b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Lib/test/test_format.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ def test_common_format(self):
278278
"unsupported format %z at position 4")
279279
test_exc_common("abc %Id", 1, ValueError,
280280
"unsupported format %I at position 4")
281+
test_exc_common("abc %'d", 1, ValueError,
282+
"stray % at position 4 or unexpected format character \"'\" at position 5")
281283
test_exc_common("abc %1 d", 1, ValueError,
282284
"stray % at position 4 or unexpected format character ' ' at position 6")
283285
test_exc_common('abc % (x)r', {}, ValueError,
@@ -365,8 +367,6 @@ def test_str_format(self):
365367
print('Testing exceptions')
366368
test_exc('abc %b', 1, ValueError,
367369
"unsupported format %b at position 4")
368-
test_exc("abc %'d", 1, ValueError,
369-
"stray % at position 4 or unexpected format character ''' (U+0027) at position 5")
370370
test_exc("abc %\nd", 1, ValueError,
371371
"stray % at position 4 or unexpected format character U+000A at position 5")
372372
test_exc("abc %\x1fd", 1, ValueError,

Objects/unicode_format.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,14 @@ unicode_format_arg_format(struct unicode_formatter_t *ctx,
770770
"unsupported format %%%c at position %zd",
771771
(int)arg->ch, arg->fmtstart);
772772
}
773-
else if (arg->ch >= 32 && arg->ch < 127 && arg->ch != '\'') {
773+
else if (arg->ch == '\'') {
774+
PyErr_Format(PyExc_ValueError,
775+
"stray %% at position %zd or unexpected "
776+
"format character \"'\" at position %zd",
777+
arg->fmtstart,
778+
ctx->fmtpos - 1);
779+
}
780+
else if (arg->ch >= 32 && arg->ch < 127) {
774781
PyErr_Format(PyExc_ValueError,
775782
"stray %% at position %zd or unexpected "
776783
"format character '%c' at position %zd",

0 commit comments

Comments
 (0)