Revert "gh-112068: C API: Add support of nullable arguments in PyArg_… · python/cpython@3a89dfe

GitHub

@@ -1429,123 +1429,6 @@ def test_nested_sequence(self):

14291429"argument 1 must be sequence of length 1, not 0"):

14301430parse(([],), {}, '('+f+')', ['a'])

143114311432-deftest_specific_type_errors(self):

1433-parse=_testcapi.parse_tuple_and_keywords

1434-1435-defcheck(format, arg, expected, got='list'):

1436-errmsg=f'must be {expected}, not {got}'

1437-withself.assertRaisesRegex(TypeError, errmsg):

1438-parse((arg,), {}, format, ['a'])

1439-1440-check('k', [], 'int')

1441-check('k?', [], 'int or None')

1442-check('K', [], 'int')

1443-check('K?', [], 'int or None')

1444-check('c', [], 'a byte string of length 1')

1445-check('c?', [], 'a byte string of length 1 or None')

1446-check('c', b'abc', 'a byte string of length 1',

1447-'a bytes object of length 3')

1448-check('c?', b'abc', 'a byte string of length 1 or None',

1449-'a bytes object of length 3')

1450-check('c', bytearray(b'abc'), 'a byte string of length 1',

1451-'a bytearray object of length 3')

1452-check('c?', bytearray(b'abc'), 'a byte string of length 1 or None',

1453-'a bytearray object of length 3')

1454-check('C', [], 'a unicode character')

1455-check('C?', [], 'a unicode character or None')

1456-check('C', 'abc', 'a unicode character',

1457-'a string of length 3')

1458-check('C?', 'abc', 'a unicode character or None',

1459-'a string of length 3')

1460-check('s', [], 'str')

1461-check('s?', [], 'str or None')

1462-check('z', [], 'str or None')

1463-check('z?', [], 'str or None')

1464-check('es', [], 'str')

1465-check('es?', [], 'str or None')

1466-check('es#', [], 'str')

1467-check('es#?', [], 'str or None')

1468-check('et', [], 'str, bytes or bytearray')

1469-check('et?', [], 'str, bytes, bytearray or None')

1470-check('et#', [], 'str, bytes or bytearray')

1471-check('et#?', [], 'str, bytes, bytearray or None')

1472-check('w*', [], 'read-write bytes-like object')

1473-check('w*?', [], 'read-write bytes-like object or None')

1474-check('S', [], 'bytes')

1475-check('S?', [], 'bytes or None')

1476-check('U', [], 'str')

1477-check('U?', [], 'str or None')

1478-check('Y', [], 'bytearray')

1479-check('Y?', [], 'bytearray or None')

1480-check('(OO)', 42, '2-item tuple', 'int')

1481-check('(OO)?', 42, '2-item tuple or None', 'int')

1482-check('(OO)', (1, 2, 3), 'tuple of length 2', '3')

1483-1484-deftest_nullable(self):

1485-parse=_testcapi.parse_tuple_and_keywords

1486-1487-defcheck(format, arg, allows_none=False):

1488-# Because some format units (such as y*) require cleanup,

1489-# we force the parsing code to perform the cleanup by adding

1490-# an argument that always fails.

1491-# By checking for an exception, we ensure that the parsing

1492-# of the first argument was successful.

1493-self.assertRaises(OverflowError, parse,

1494- (arg, 256), {}, format+'?b', ['a', 'b'])

1495-self.assertRaises(OverflowError, parse,

1496- (None, 256), {}, format+'?b', ['a', 'b'])

1497-self.assertRaises(OverflowError, parse,

1498- (arg, 256), {}, format+'b', ['a', 'b'])

1499-self.assertRaises(OverflowErrorifallows_noneelseTypeError, parse,

1500- (None, 256), {}, format+'b', ['a', 'b'])

1501-1502-check('b', 42)

1503-check('B', 42)

1504-check('h', 42)

1505-check('H', 42)

1506-check('i', 42)

1507-check('I', 42)

1508-check('n', 42)

1509-check('l', 42)

1510-check('k', 42)

1511-check('L', 42)

1512-check('K', 42)

1513-check('f', 2.5)

1514-check('d', 2.5)

1515-check('D', 2.5j)

1516-check('c', b'a')

1517-check('C', 'a')

1518-check('p', True, allows_none=True)

1519-check('y', b'buffer')

1520-check('y*', b'buffer')

1521-check('y#', b'buffer')

1522-check('s', 'string')

1523-check('s*', 'string')

1524-check('s#', 'string')

1525-check('z', 'string', allows_none=True)

1526-check('z*', 'string', allows_none=True)

1527-check('z#', 'string', allows_none=True)

1528-check('w*', bytearray(b'buffer'))

1529-check('U', 'string')

1530-check('S', b'bytes')

1531-check('Y', bytearray(b'bytearray'))

1532-check('O', object, allows_none=True)

1533-1534-check('(OO)', (1, 2))

1535-self.assertEqual(parse((((1, 2), 3),), {}, '((OO)?O)', ['a']), (1, 2, 3))

1536-self.assertEqual(parse(((None, 3),), {}, '((OO)?O)', ['a']), (NULL, NULL, 3))

1537-self.assertEqual(parse((((1, 2), 3),), {}, '((OO)O)', ['a']), (1, 2, 3))

1538-self.assertRaises(TypeError, parse, ((None, 3),), {}, '((OO)O)', ['a'])

1539-1540-parse((None,), {}, 'es?', ['a'])

1541-parse((None,), {}, 'es#?', ['a'])

1542-parse((None,), {}, 'et?', ['a'])

1543-parse((None,), {}, 'et#?', ['a'])

1544-parse((None,), {}, 'O!?', ['a'])

1545-parse((None,), {}, 'O&?', ['a'])

1546-1547-# TODO: More tests for es?, es#?, et?, et#?, O!, O&

[email protected](_testinternalcapiisNone, 'needs _testinternalcapi')

15501433deftest_gh_119213(self):

15511434rc, out, err=script_helper.assert_python_ok("-c", """if True: