[Python-checkins] gh-94864: Fix PyArg_Parse* with deprecated format units "u" and "Z" (GH-94902)

miss-islington webhook-mailer at python.org
Sun Jul 17 01:46:52 EDT 2022


https://github.com/python/cpython/commit/31608abf55839f5fa9cce33d530e35ea6e0ad427
commit: 31608abf55839f5fa9cce33d530e35ea6e0ad427
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-07-16T22:46:43-07:00
summary:

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 107c21c5d56682320b38c01b5575c1604a429239)

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

files:
A Misc/NEWS.d/next/C API/2022-07-16-14-57-23.gh-issue-94864.Pb41ab.rst
M Lib/test/test_getargs2.py
M Python/getargs.c

diff --git a/Lib/test/test_getargs2.py b/Lib/test/test_getargs2.py
index e0db9e40e650b..571cabb5f13a0 100644
--- a/Lib/test/test_getargs2.py
+++ b/Lib/test/test_getargs2.py
@@ -2,6 +2,7 @@
 import math
 import string
 import sys
+import warnings
 from test import support
 from test.support import import_helper
 from test.support import warnings_helper
@@ -999,6 +1000,9 @@ def test_u(self):
             self.assertRaises(TypeError, getargs_u, memoryview(b'memoryview'))
         with self.assertWarns(DeprecationWarning):
             self.assertRaises(TypeError, getargs_u, None)
+        with warnings.catch_warnings():
+            warnings.simplefilter('error', DeprecationWarning)
+            self.assertRaises(DeprecationWarning, getargs_u, 'abc\xe9')
 
     @support.requires_legacy_unicode_capi
     def test_u_hash(self):
@@ -1015,6 +1019,9 @@ def test_u_hash(self):
             self.assertRaises(TypeError, getargs_u_hash, memoryview(b'memoryview'))
         with self.assertWarns(DeprecationWarning):
             self.assertRaises(TypeError, getargs_u_hash, None)
+        with warnings.catch_warnings():
+            warnings.simplefilter('error', DeprecationWarning)
+            self.assertRaises(DeprecationWarning, getargs_u_hash, 'abc\xe9')
 
     @support.requires_legacy_unicode_capi
     def test_Z(self):
@@ -1031,6 +1038,9 @@ def test_Z(self):
             self.assertRaises(TypeError, getargs_Z, memoryview(b'memoryview'))
         with self.assertWarns(DeprecationWarning):
             self.assertIsNone(getargs_Z(None))
+        with warnings.catch_warnings():
+            warnings.simplefilter('error', DeprecationWarning)
+            self.assertRaises(DeprecationWarning, getargs_Z, 'abc\xe9')
 
     @support.requires_legacy_unicode_capi
     def test_Z_hash(self):
@@ -1047,6 +1057,9 @@ def test_Z_hash(self):
             self.assertRaises(TypeError, getargs_Z_hash, memoryview(b'memoryview'))
         with self.assertWarns(DeprecationWarning):
             self.assertIsNone(getargs_Z_hash(None))
+        with warnings.catch_warnings():
+            warnings.simplefilter('error', DeprecationWarning)
+            self.assertRaises(DeprecationWarning, getargs_Z_hash, 'abc\xe9')
 
 
 class Object_TestCase(unittest.TestCase):
diff --git a/Misc/NEWS.d/next/C API/2022-07-16-14-57-23.gh-issue-94864.Pb41ab.rst b/Misc/NEWS.d/next/C API/2022-07-16-14-57-23.gh-issue-94864.Pb41ab.rst
new file mode 100644
index 0000000000000..ed2a954778020
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2022-07-16-14-57-23.gh-issue-94864.Pb41ab.rst	
@@ -0,0 +1,2 @@
+Fix ``PyArg_Parse*`` with deprecated format units "u" and "Z". It returned 1
+(success) when warnings are turned into exceptions.
diff --git a/Python/getargs.c b/Python/getargs.c
index d5e083509efef..92fc0aff322d2 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -1016,7 +1016,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
     {
         if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
                 "getargs: The '%c' format is deprecated. Use 'U' instead.", c)) {
-            return NULL;
+            RETURN_ERR_OCCURRED;
         }
 _Py_COMP_DIAG_PUSH
 _Py_COMP_DIAG_IGNORE_DEPR_DECLS



More information about the Python-checkins mailing list