8000 [3.11] gh-112438: Fix support of format units with the "e" prefix in … · python/cpython@581b244 · GitHub
[go: up one dir, main page]

Skip to content

Commit 581b244

Browse files
[3.11] gh-112438: Fix support of format units with the "e" prefix in nested tuples in PyArg_Parse (gh-112439) (GH-112461)
(cherry picked from commit 4eea1e8)
1 parent 6d9b181 commit 581b244

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

Lib/test/test_capi/test_getargs.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,33 @@ def test_positional_only(self):
13221322
with self.assertRaisesRegex(SystemError, 'Empty keyword'):
13231323
parse((1,), {}, 'O|OO', ['', 'a', ''])
13241324

1325+
def test_nested_tuple(self):
1326+
parse = _testcapi.parse_tuple_and_keywords
1327+
1328+
parse(((1, 2, 3),), {}, '(OOO)', ['a'])
1329+
parse((1, (2, 3), 4), {}, 'O(OO)O', ['a', 'b', 'c'])
1330+
parse(((1, 2, 3),), {}, '(iii)', ['a'])
1331+
1332+
with self.assertRaisesRegex(TypeError,
1333+
"argument 1 must be sequence of length 2, not 3"):
1334+
parse(((1, 2, 3),), {}, '(ii)', ['a'])
1335+
with self.assertRaisesRegex(TypeError,
1336+
"argument 1 must be sequence of length 2, not 1"):
1337+
parse(((1,),), {}, '(ii)', ['a'])
1338+
with self.assertRaisesRegex(TypeError,
1339+
"argument 1 must be 2-item sequence, not int"):
1340+
parse((1,), {}, '(ii)', ['a'])
1341+
with self.assertRaisesRegex(TypeError,
1342+
"argument 1 must be 2-item sequence, not bytes"):
1343+
parse((b'ab',), {}, '(ii)', ['a'])
1344+
1345+
for f in 'es', 'et', 'es#', 'et#':
1346+
with self.assertRaises(LookupError): # empty encoding ""
1347+
parse((('a',),), {}, '(' + f + ')', ['a'])
1348+
with self.assertRaisesRegex(TypeError,
1349+
"argument 1 must be sequence of length 1, not 0"):
1350+
parse(((),), {}, '(' + f + ')', ['a'])
1351+
13251352

13261353
class Test_testcapi(unittest.TestCase):
13271354
locals().update((name, getattr(_testcapi, name))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix support of format units "es", "et", "es#", and "et#" in nested tuples in
2+
:c:func:`PyArg_ParseTuple`-like functions.

Python/getargs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
522522
}
523523
else if (c == ':' || c == ';' || c == '\0')
524524
break;
525-
else if (level == 0 && Py_ISALPHA(c))
525+
else if (level == 0 && Py_ISALPHA(c) && c != 'e')
526526
n++;
527527
}
528528

0 commit comments

Comments
 (0)
0