Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/test/test_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion Modules/_sre.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,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;
}

Expand Down