Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Lib/test/test_getargs2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix ``PyArg_Parse*`` with deprecated format units "u" and "Z". It returned 1
(success) when warnings are turned into exceptions.
2 changes: 1 addition & 1 deletion Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down