Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Next Next commit
gh-117557: Raise ValueError iso. TypeError if str length is wrong for…
… int(accept={str}) Argument Clinic converter
  • Loading branch information
erlend-aasland committed Apr 5, 2024
commit 6b1d95666f558a41ca3d0760175c560c9179150f
4 changes: 2 additions & 2 deletions Lib/test/clinic.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ test_int_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
goto exit;
}
if (PyUnicode_GET_LENGTH(args[2]) != 1) {
_PyArg_BadArgument("test_int_converter", "argument 3", "a unicode character", args[2]);
PyErr_SetString(PyExc_ValueError, "a single unicode character expected");
goto exit;
}
c = PyUnicode_READ_CHAR(args[2], 0);
Expand All @@ -1048,7 +1048,7 @@ test_int_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)

static PyObject *
test_int_converter_impl(PyObject *module, int a, int b, int c, myenum d)
/*[clinic end generated code: output=5aed87a7589eefb2 input=d20541fc1ca0553e]*/
/*[clinic end generated code: output=ec176dff0664c4a5 input=d20541fc1ca0553e]*/


/*[clinic input]
Expand Down
20 changes: 10 additions & 10 deletions Lib/test/test_unicodedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_digit(self):
self.assertEqual(self.db.digit('\U0001D7FD'), 7)

self.assertRaises(TypeError, self.db.digit)
self.assertRaises(TypeError, self.db.digit, 'xx')
self.assertRaises(ValueError, self.db.digit, 'xx')
self.assertRaises(ValueError, self.db.digit, 'x')

def test_numeric(self):
Expand All @@ -146,7 +146,7 @@ def test_numeric(self):
self.assertEqual(self.db.numeric('\U0001012A'), 9000)

self.assertRaises(TypeError, self.db.numeric)
self.assertRaises(TypeError, self.db.numeric, 'xx')
self.assertRaises(ValueError, self.db.numeric, 'xx')
self.assertRaises(ValueError, self.db.numeric, 'x')

def test_decimal(self):
Expand All @@ -158,7 +158,7 @@ def test_decimal(self):
self.assertEqual(self.db.decimal('\U0001D7FD'), 7)

self.assertRaises(TypeError, self.db.decimal)
self.assertRaises(TypeError, self.db.decimal, 'xx')
self.assertRaises(ValueError, self.db.decimal, 'xx')
self.assertRaises(ValueError, self.db.decimal, 'x')

def test_category(self):
Expand All @@ -169,7 +169,7 @@ def test_category(self):
self.assertEqual(self.db.category('\U0001012A'), 'No')

self.assertRaises(TypeError, self.db.category)
self.assertRaises(TypeError, self.db.category, 'xx')
self.assertRaises(ValueError, self.db.category, 'xx')

def test_bidirectional(self):
self.assertEqual(self.db.bidirectional('\uFFFE'), '')
Expand All @@ -178,14 +178,14 @@ def test_bidirectional(self):
self.assertEqual(self.db.bidirectional('\U00020000'), 'L')

self.assertRaises(TypeError, self.db.bidirectional)
self.assertRaises(TypeError, self.db.bidirectional, 'xx')
self.assertRaises(ValueError, self.db.bidirectional, 'xx')

def test_decomposition(self):
self.assertEqual(self.db.decomposition('\uFFFE'),'')
self.assertEqual(self.db.decomposition('\u00bc'), '<fraction> 0031 2044 0034')

self.assertRaises(TypeError, self.db.decomposition)
self.assertRaises(TypeError, self.db.decomposition, 'xx')
self.assertRaises(ValueError, self.db.decomposition, 'xx')

def test_mirrored(self):
self.assertEqual(self.db.mirrored('\uFFFE'), 0)
Expand All @@ -194,7 +194,7 @@ def test_mirrored(self):
self.assertEqual(self.db.mirrored('\U00020000'), 0)

self.assertRaises(TypeError, self.db.mirrored)
self.assertRaises(TypeError, self.db.mirrored, 'xx')
self.assertRaises(ValueError, self.db.mirrored, 'xx')

def test_combining(self):
self.assertEqual(self.db.combining('\uFFFE'), 0)
Expand All @@ -203,7 +203,7 @@ def test_combining(self):
self.assertEqual(self.db.combining('\U00020000'), 0)

self.assertRaises(TypeError, self.db.combining)
self.assertRaises(TypeError, self.db.combining, 'xx')
self.assertRaises(ValueError, self.db.combining, 'xx')

def test_pr29(self):
# https://www.unicode.org/review/pr-29.html
Expand Down Expand Up @@ -239,8 +239,8 @@ def test_east_asian_width(self):
eaw = self.db.east_asian_width
self.assertRaises(TypeError, eaw, b'a')
self.assertRaises(TypeError, eaw, bytearray())
self.assertRaises(TypeError, eaw, '')
self.assertRaises(TypeError, eaw, 'ra')
self.assertRaises(ValueError, eaw, '')
self.assertRaises(ValueError, eaw, 'ra')
self.assertEqual(eaw('\x1e'), 'N')
self.assertEqual(eaw('\x20'), 'Na')
self.assertEqual(eaw('\uC894'), 'W')
Expand Down
4 changes: 2 additions & 2 deletions Modules/clinic/_testclinic.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Modules/clinic/arraymodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions Modules/clinic/unicodedata.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions PC/clinic/msvcrtmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Tools/clinic/libclinic/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> st
goto exit;
}}}}
if (PyUnicode_GET_LENGTH({argname}) != 1) {{{{
{bad_argument}
PyErr_SetString(PyExc_ValueError, "a single unicode character expected");
goto exit;
}}}}
{paramname} = PyUnicode_READ_CHAR({argname}, 0);
Expand Down