mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
[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 4eea1e8236
)
This commit is contained in:
parent
6d9b1819b8
commit
581b244155
3 changed files with 30 additions and 1 deletions
|
@ -1322,6 +1322,33 @@ class ParseTupleAndKeywords_Test(unittest.TestCase):
|
|||
with self.assertRaisesRegex(SystemError, 'Empty keyword'):
|
||||
parse((1,), {}, 'O|OO', ['', 'a', ''])
|
||||
|
||||
def test_nested_tuple(self):
|
||||
parse = _testcapi.parse_tuple_and_keywords
|
||||
|
||||
parse(((1, 2, 3),), {}, '(OOO)', ['a'])
|
||||
parse((1, (2, 3), 4), {}, 'O(OO)O', ['a', 'b', 'c'])
|
||||
parse(((1, 2, 3),), {}, '(iii)', ['a'])
|
||||
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
"argument 1 must be sequence of length 2, not 3"):
|
||||
parse(((1, 2, 3),), {}, '(ii)', ['a'])
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
"argument 1 must be sequence of length 2, not 1"):
|
||||
parse(((1,),), {}, '(ii)', ['a'])
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
"argument 1 must be 2-item sequence, not int"):
|
||||
parse((1,), {}, '(ii)', ['a'])
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
"argument 1 must be 2-item sequence, not bytes"):
|
||||
parse((b'ab',), {}, '(ii)', ['a'])
|
||||
|
||||
for f in 'es', 'et', 'es#', 'et#':
|
||||
with self.assertRaises(LookupError): # empty encoding ""
|
||||
parse((('a',),), {}, '(' + f + ')', ['a'])
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
"argument 1 must be sequence of length 1, not 0"):
|
||||
parse(((),), {}, '(' + f + ')', ['a'])
|
||||
|
||||
|
||||
class Test_testcapi(unittest.TestCase):
|
||||
locals().update((name, getattr(_testcapi, name))
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Fix support of format units "es", "et", "es#", and "et#" in nested tuples in
|
||||
:c:func:`PyArg_ParseTuple`-like functions.
|
|
@ -522,7 +522,7 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
|||
}
|
||||
else if (c == ':' || c == ';' || c == '\0')
|
||||
break;
|
||||
else if (level == 0 && Py_ISALPHA(c))
|
||||
else if (level == 0 && Py_ISALPHA(c) && c != 'e')
|
||||
n++;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue