Skip to content

Commit 31608ab

Browse files
gh-94864: Fix PyArg_Parse* with deprecated format units "u" and "Z" (GH-94902)
It returned 1 (success) when warnings are turned into exceptions. (cherry picked from commit 107c21c) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 964431e commit 31608ab

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Lib/test/test_getargs2.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import math
33
import string
44
import sys
5+
import warnings
56
from test import support
67
from test.support import import_helper
78
from test.support import warnings_helper
@@ -999,6 +1000,9 @@ def test_u(self):
9991000
self.assertRaises(TypeError, getargs_u, memoryview(b'memoryview'))
10001001
with self.assertWarns(DeprecationWarning):
10011002
self.assertRaises(TypeError, getargs_u, None)
1003+
with warnings.catch_warnings():
1004+
warnings.simplefilter('error', DeprecationWarning)
1005+
self.assertRaises(DeprecationWarning, getargs_u, 'abc\xe9')
10021006

10031007
@support.requires_legacy_unicode_capi
10041008
def test_u_hash(self):
@@ -1015,6 +1019,9 @@ def test_u_hash(self):
10151019
self.assertRaises(TypeError, getargs_u_hash, memoryview(b'memoryview'))
10161020
with self.assertWarns(DeprecationWarning):
10171021
self.assertRaises(TypeError, getargs_u_hash, None)
1022+
with warnings.catch_warnings():
1023+
warnings.simplefilter('error', DeprecationWarning)
1024+
self.assertRaises(DeprecationWarning, getargs_u_hash, 'abc\xe9')
10181025

10191026
@support.requires_legacy_unicode_capi
10201027
def test_Z(self):
@@ -1031,6 +1038,9 @@ def test_Z(self):
10311038
self.assertRaises(TypeError, getargs_Z, memoryview(b'memoryview'))
10321039
with self.assertWarns(DeprecationWarning):
10331040
self.assertIsNone(getargs_Z(None))
1041+
with warnings.catch_warnings():
1042+
warnings.simplefilter('error', DeprecationWarning)
1043+
self.assertRaises(DeprecationWarning, getargs_Z, 'abc\xe9')
10341044

10351045
@support.requires_legacy_unicode_capi
10361046
def test_Z_hash(self):
@@ -1047,6 +1057,9 @@ def test_Z_hash(self):
10471057
self.assertRaises(TypeError, getargs_Z_hash, memoryview(b'memoryview'))
10481058
with self.assertWarns(DeprecationWarning):
10491059
self.assertIsNone(getargs_Z_hash(None))
1060+
with warnings.catch_warnings():
1061+
warnings.simplefilter('error', DeprecationWarning)
1062+
self.assertRaises(DeprecationWarning, getargs_Z_hash, 'abc\xe9')
10501063

10511064

10521065
class Object_TestCase(unittest.TestCase):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``PyArg_Parse*`` with deprecated format units "u" and "Z". It returned 1
2+
(success) when warnings are turned into exceptions.

Python/getargs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
10161016
{
10171017
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
10181018
"getargs: The '%c' format is deprecated. Use 'U' instead.", c)) {
1019-
return NULL;
1019+
RETURN_ERR_OCCURRED;
10201020
}
10211021
_Py_COMP_DIAG_PUSH
10221022
_Py_COMP_DIAG_IGNORE_DEPR_DECLS

0 commit comments

Comments
 (0)