From 38255f6fe2239b05fe62fd88fc694b2b97b6abd1 Mon Sep 17 00:00:00 2001 From: ApostolFet Date: Sat, 8 Mar 2025 01:02:39 +0300 Subject: [PATCH 1/4] fix: error message on %i format --- Objects/bytesobject.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index b3d1c425ad18b7..fb735adf869534 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -468,8 +468,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)) { From 19ee22982449782aef47f7aa1dd12a1f4081b019 Mon Sep 17 00:00:00 2001 From: ApostolFet Date: Sun, 9 Mar 2025 11:40:30 +0300 Subject: [PATCH 2/4] test: error message on %i format --- Lib/test/test_bytes.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index f6ffe83c5d69e8..65b999308c7d25 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -5,6 +5,7 @@ """ import array +import operator import os import re import sys @@ -751,6 +752,8 @@ 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) + def test_imod(self): b = self.type2test(b'hello, %b!') orig = b From 8a2a2034efc0262857f77655ed15b7dcd1c20229 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 9 Mar 2025 09:03:26 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2025-03-09-09-03-24.gh-issue-130928.gP1yKv.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-03-09-09-03-24.gh-issue-130928.gP1yKv.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-03-09-09-03-24.gh-issue-130928.gP1yKv.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-09-09-03-24.gh-issue-130928.gP1yKv.rst new file mode 100644 index 00000000000000..f9f144a80aa6c6 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-09-09-03-24.gh-issue-130928.gP1yKv.rst @@ -0,0 +1,2 @@ +Fix error message when formatting bytes using the ``'i'`` flag. +Patch by Maxim Ageev. From f1dfd8a8b4217891fd91e50d3d2fde14442518b3 Mon Sep 17 00:00:00 2001 From: Ageev Maxim <90645107+ApostolFet@users.noreply.github.com> Date: Sun, 9 Mar 2025 15:59:30 +0300 Subject: [PATCH 4/4] test: error message on %d format Co-authored-by: sobolevn --- Lib/test/test_bytes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index 65b999308c7d25..42e7427725d2d7 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -753,6 +753,7 @@ def check(fmt, vals, result): 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!')