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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/test_cprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ def test_throw(self):
self.assertEqual(cc, 1)
self.assertEqual(nc, 1)

def test_bad_descriptor(self):
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that this is used above, but I am not a fan of docstrings in unittests :( Docstrings can be shown during test execution.

Let's maybe convert it to comments?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have problem converting it to comments, but it seems to be pretty random if we do it case by case. I think we have plenty of docstrings in our test suite. I always use python -m test for stdlib tests so the docstring never bothers me. Do you use unittest directly for these tests? If we want to even soft-enforce this, we should probably discuss it among some core devs and put it somewhere in the devguide. Most people won't be able to see it, but we can refer to it during code reviews and we can gradually make it happen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I converted this to a comment - I don't have a strong opinion on this (it's easier to do a docstring if the description is long so I normally just do a docstring). If you believe this actually matters in some cases, we should probably discuss it and put it to somewhere in devguide. It would be helpful for people like us to make a decision and get use to it :)

gh-132250
cProfile should not crash when the profiler callback fails to locate
the actual function of a method.
"""
with self.profilerclass() as prof:
with self.assertRaises(TypeError):
bytes.find(str())


class TestCommandLine(unittest.TestCase):
def test_sort(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed the :exc:`SystemError` in :mod:`cProfile` when locating the actual c function of a method raises an exception.
1 change: 1 addition & 0 deletions Modules/_lsprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ PyObject* get_cfunc_from_callable(PyObject* callable, PyObject* self_arg, PyObje
PyObject *meth = Py_TYPE(callable)->tp_descr_get(
callable, self_arg, (PyObject*)Py_TYPE(self_arg));
if (meth == NULL) {
PyErr_Clear();
return NULL;
}
if (PyCFunction_Check(meth)) {
Expand Down
Loading