Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit683bcc5

Browse files
serhiy-storchakamiss-islington
authored andcommitted
pythongh-94864: Fix PyArg_Parse* with deprecated format units "u" and "Z" (pythonGH-94902)
It returned 1 (success) when warnings are turned into exceptions.(cherry picked from commit107c21c)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent964431e commit683bcc5

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
importmath
33
importstring
44
importsys
5+
importwarnings
56
fromtestimportsupport
67
fromtest.supportimportimport_helper
78
fromtest.supportimportwarnings_helper
@@ -999,6 +1000,9 @@ def test_u(self):
9991000
self.assertRaises(TypeError,getargs_u,memoryview(b'memoryview'))
10001001
withself.assertWarns(DeprecationWarning):
10011002
self.assertRaises(TypeError,getargs_u,None)
1003+
withwarnings.catch_warnings():
1004+
warnings.simplefilter('error',DeprecationWarning)
1005+
self.assertRaises(DeprecationWarning,getargs_u,'abc\xe9')
10021006

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

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

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

10511064

10521065
classObject_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-
returnNULL;
1019+
RETURN_ERR_OCCURRED;
10201020
}
10211021
_Py_COMP_DIAG_PUSH
10221022
_Py_COMP_DIAG_IGNORE_DEPR_DECLS

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp