mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-130928: Fix error message during bytes formatting for the 'i' flag (#130967)
This commit is contained in:
parent
929afd1d6e
commit
7c3692fe27
4 changed files with 10 additions and 2 deletions
|
|
@ -5,6 +5,7 @@
|
|||
"""
|
||||
|
||||
import array
|
||||
import operator
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
|
@ -771,6 +772,9 @@ def check(fmt, vals, result):
|
|||
check(b'%i%b %*.*b', (10, b'3', 5, 3, b'abc',), b'103 abc')
|
||||
check(b'%c', b'a', b'a')
|
||||
|
||||
self.assertRaisesRegex(TypeError, '%i format: a real number is required, not complex', operator.mod, '%i', 2j)
|
||||
self.assertRaisesRegex(TypeError, '%d format: a real number is required, not complex', operator.mod, '%d', 2j)
|
||||
|
||||
def test_imod(self):
|
||||
b = self.type2test(b'hello, %b!')
|
||||
orig = b
|
||||
|
|
|
|||
|
|
@ -283,6 +283,10 @@ def test_common_format(self):
|
|||
"%x format: an integer is required, not str")
|
||||
test_exc_common('%x', 3.14, TypeError,
|
||||
"%x format: an integer is required, not float")
|
||||
test_exc_common('%i', '1', TypeError,
|
||||
"%i format: a real number is required, not str")
|
||||
test_exc_common('%i', b'1', TypeError,
|
||||
"%i format: a real number is required, not bytes")
|
||||
|
||||
def test_str_format(self):
|
||||
testformat("%r", "\u0378", "'\\u0378'") # non printable
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Fix error message when formatting bytes using the ``'i'`` flag.
|
||||
Patch by Maxim Ageev.
|
||||
|
|
@ -469,8 +469,6 @@ static PyObject *
|
|||
formatlong(PyObject *v, int flags, int prec, int type)
|
||||
{
|
||||
PyObject *result, *iobj;
|
||||
if (type == 'i')
|
||||
type = 'd';
|
||||
if (PyLong_Check(v))
|
||||
return _PyUnicode_FormatLong(v, flags & F_ALT, prec, type);
|
||||
if (PyNumber_Check(v)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue