Skip to content

Commit c5f925c

Browse files
gh-122029: Move monitoring after method expand for CALL_KW (GH-130488)
1 parent 3774d9f commit c5f925c

File tree

4 files changed

+45
-28
lines changed

4 files changed

+45
-28
lines changed

Lib/test/test_sys_setprofile.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,24 @@ class A:
493493
# The last c_call is the call to sys.setprofile
494494
self.assertEqual(events, ['c_call', 'c_return', 'c_call'])
495495

496+
class B:
497+
f = classmethod(max)
498+
events = []
499+
sys.setprofile(lambda frame, event, args: events.append(event))
500+
# Not important, we only want to trigger INSTRUMENTED_CALL_KW
501+
B().f(1, key=lambda x: 0)
502+
sys.setprofile(None)
503+
# The last c_call is the call to sys.setprofile
504+
self.assertEqual(
505+
events,
506+
['c_call',
507+
'call', 'return',
508+
'call', 'return',
509+
'c_return',
510+
'c_call'
511+
]
512+
)
513+
496514

497515
if __name__ == "__main__":
498516
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``INSTRUMENTED_CALL_KW`` will expand the method before monitoring to reflect the actual behavior more accurately.

Python/bytecodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4509,8 +4509,8 @@ dummy_func(
45094509
macro(INSTRUMENTED_CALL_KW) =
45104510
counter/1 +
45114511
unused/2 +
4512-
_MONITOR_CALL_KW +
45134512
_MAYBE_EXPAND_METHOD_KW +
4513+
_MONITOR_CALL_KW +
45144514
_DO_CALL_KW;
45154515

45164516
op(_CHECK_IS_NOT_PY_CALLABLE_KW, (callable[1], unused[1], unused[oparg], kwnames -- callable[1], unused[1], unused[oparg], kwnames)) {

Python/generated_cases.c.h

Lines changed: 25 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)