mirror of
https://github.com/python/cpython.git
synced 2025-08-09 19:38:42 +00:00
[3.12] gh-122029: Log call events in sys.setprofile when it's a method with c function (GH-122072) (GH-122206)
gh-122029: Log call events in sys.setprofile when it's a method with c function (GH-122072)
Log call events in sys.setprofile when it is a method with a C function.
(cherry picked from commit e91ef13861
)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
This commit is contained in:
parent
d7c67e0aca
commit
257c413cd1
3 changed files with 28 additions and 0 deletions
|
@ -478,6 +478,20 @@ class TestEdgeCases(unittest.TestCase):
|
|||
sys.setprofile(lambda *args: None)
|
||||
f()
|
||||
|
||||
def test_method_with_c_function(self):
|
||||
# gh-122029
|
||||
# When we have a PyMethodObject whose im_func is a C function, we
|
||||
# should record both the call and the return. f = classmethod(repr)
|
||||
# is just a way to create a PyMethodObject with a C function.
|
||||
class A:
|
||||
f = classmethod(repr)
|
||||
events = []
|
||||
sys.setprofile(lambda frame, event, args: events.append(event))
|
||||
A().f()
|
||||
sys.setprofile(None)
|
||||
# The last c_call is the call to sys.setprofile
|
||||
self.assertEqual(events, ['c_call', 'c_return', 'c_call'])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue