]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-94864: Fix PyArg_Parse* with deprecated format units "u" and "Z" (GH-94902)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 17 Jul 2022 05:46:43 +0000 (22:46 -0700)
committerGitHub <noreply@github.com>
Sun, 17 Jul 2022 05:46:43 +0000 (22:46 -0700)
It returned 1 (success) when warnings are turned into exceptions.
(cherry picked from commit 107c21c5d56682320b38c01b5575c1604a429239)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_getargs2.py
Misc/NEWS.d/next/C API/2022-07-16-14-57-23.gh-issue-94864.Pb41ab.rst [new file with mode: 0644]
Python/getargs.c

index e0db9e40e650b6a0f0ed9209134e4e4196bc434c..571cabb5f13a02ad5465cde78dc93727ad785196 100644 (file)
@@ -2,6 +2,7 @@ import unittest
 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 @@ class String_TestCase(unittest.TestCase):
             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 @@ class String_TestCase(unittest.TestCase):
             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 @@ class String_TestCase(unittest.TestCase):
             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 @@ class String_TestCase(unittest.TestCase):
             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 (file)
index 0000000..ed2a954
--- /dev/null
@@ -0,0 +1,2 @@
+Fix ``PyArg_Parse*`` with deprecated format units "u" and "Z". It returned 1
+(success) when warnings are turned into exceptions.
index d5e083509efefc7df5399f1f4f6d826db878fd3b..92fc0aff322d26b1522ff8806831a2460c27457f 100644 (file)
@@ -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