Skip to content

Commit 8f706d1

Browse files
Clear error in lsprof callback when method descriptor raises an exception
1 parent ef06508 commit 8f706d1

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Lib/test/test_cprofile.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ def test_throw(self):
139139
self.assertEqual(cc, 1)
140140
self.assertEqual(nc, 1)
141141

142+
def test_bad_descriptor(self):
143+
"""
144+
gh-132250
145+
cProfile should not crash when profiling a function with a descriptor
146+
that raises an exception.
147+
"""
148+
with self.profilerclass() as prof:
149+
with self.assertRaises(TypeError):
150+
bytes.find(str())
151+
142152

143153
class TestCommandLine(unittest.TestCase):
144154
def test_sort(self):

Modules/_lsprof.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ PyObject* get_cfunc_from_callable(PyObject* callable, PyObject* self_arg, PyObje
671671
PyObject *meth = Py_TYPE(callable)->tp_descr_get(
672672
callable, self_arg, (PyObject*)Py_TYPE(self_arg));
673673
if (meth == NULL) {
674+
PyErr_Clear();
674675
return NULL;
675676
}
676677
if (PyCFunction_Check(meth)) {

0 commit comments

Comments
 (0)