mirror of https://github.com/python/cpython.git
bpo-40736: Improve the error message for re.search() TypeError (GH-23312)
Include the invalid type in the error message.
This commit is contained in:
parent
498383c019
commit
6cc8ac9499
|
@ -2104,6 +2104,12 @@ def test_bug_34294(self):
|
|||
{'tag': 'foo', 'text': None},
|
||||
{'tag': 'foo', 'text': None}])
|
||||
|
||||
def test_bug_40736(self):
|
||||
with self.assertRaisesRegex(TypeError, "got 'int'"):
|
||||
re.search("x*", 5)
|
||||
with self.assertRaisesRegex(TypeError, "got 'type'"):
|
||||
re.search("x*", type)
|
||||
|
||||
|
||||
class PatternReprTests(unittest.TestCase):
|
||||
def check(self, pattern, expected):
|
||||
|
|
|
@ -389,7 +389,8 @@ getstring(PyObject* string, Py_ssize_t* p_length,
|
|||
|
||||
/* get pointer to byte string buffer */
|
||||
if (PyObject_GetBuffer(string, view, PyBUF_SIMPLE) != 0) {
|
||||
PyErr_SetString(PyExc_TypeError, "expected string or bytes-like object");
|
||||
PyErr_Format(PyExc_TypeError, "expected string or bytes-like "
|
||||
"object, got '%.200s'", Py_TYPE(string)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue