mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-94864: Fix PyArg_Parse* with deprecated format units "u" and "Z" (GH-94902)
It returned 1 (success) when warnings are turned into exceptions.
This commit is contained in:
parent
30f28ac296
commit
107c21c5d5
3 changed files with 16 additions and 1 deletions
|
@ -2,6 +2,7 @@ import unittest
|
||||||
import math
|
import math
|
||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
|
import warnings
|
||||||
from test import support
|
from test import support
|
||||||
from test.support import import_helper
|
from test.support import import_helper
|
||||||
from test.support import warnings_helper
|
from test.support import warnings_helper
|
||||||
|
@ -999,6 +1000,9 @@ class String_TestCase(unittest.TestCase):
|
||||||
self.assertRaises(TypeError, getargs_u, memoryview(b'memoryview'))
|
self.assertRaises(TypeError, getargs_u, memoryview(b'memoryview'))
|
||||||
with self.assertWarns(DeprecationWarning):
|
with self.assertWarns(DeprecationWarning):
|
||||||
self.assertRaises(TypeError, getargs_u, None)
|
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
|
@support.requires_legacy_unicode_capi
|
||||||
def test_u_hash(self):
|
def test_u_hash(self):
|
||||||
|
@ -1015,6 +1019,9 @@ class String_TestCase(unittest.TestCase):
|
||||||
self.assertRaises(TypeError, getargs_u_hash, memoryview(b'memoryview'))
|
self.assertRaises(TypeError, getargs_u_hash, memoryview(b'memoryview'))
|
||||||
with self.assertWarns(DeprecationWarning):
|
with self.assertWarns(DeprecationWarning):
|
||||||
self.assertRaises(TypeError, getargs_u_hash, None)
|
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
|
@support.requires_legacy_unicode_capi
|
||||||
def test_Z(self):
|
def test_Z(self):
|
||||||
|
@ -1031,6 +1038,9 @@ class String_TestCase(unittest.TestCase):
|
||||||
self.assertRaises(TypeError, getargs_Z, memoryview(b'memoryview'))
|
self.assertRaises(TypeError, getargs_Z, memoryview(b'memoryview'))
|
||||||
with self.assertWarns(DeprecationWarning):
|
with self.assertWarns(DeprecationWarning):
|
||||||
self.assertIsNone(getargs_Z(None))
|
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
|
@support.requires_legacy_unicode_capi
|
||||||
def test_Z_hash(self):
|
def test_Z_hash(self):
|
||||||
|
@ -1047,6 +1057,9 @@ class String_TestCase(unittest.TestCase):
|
||||||
self.assertRaises(TypeError, getargs_Z_hash, memoryview(b'memoryview'))
|
self.assertRaises(TypeError, getargs_Z_hash, memoryview(b'memoryview'))
|
||||||
with self.assertWarns(DeprecationWarning):
|
with self.assertWarns(DeprecationWarning):
|
||||||
self.assertIsNone(getargs_Z_hash(None))
|
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):
|
class Object_TestCase(unittest.TestCase):
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix ``PyArg_Parse*`` with deprecated format units "u" and "Z". It returned 1
|
||||||
|
(success) when warnings are turned into exceptions.
|
|
@ -1017,7 +1017,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
||||||
{
|
{
|
||||||
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
|
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
|
||||||
"getargs: The '%c' format is deprecated. Use 'U' instead.", c)) {
|
"getargs: The '%c' format is deprecated. Use 'U' instead.", c)) {
|
||||||
return NULL;
|
RETURN_ERR_OCCURRED;
|
||||||
}
|
}
|
||||||
_Py_COMP_DIAG_PUSH
|
_Py_COMP_DIAG_PUSH
|
||||||
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
|
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue