◐ Shell
clean mode source ↗

gh-122029: Move monitoring after method expand for CALL_KW by gaogaotiantian · Pull Request #130488 · python/cpython

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-122029: Move monitoring after method expand for CALL_KW #130488

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

18 changes: 18 additions & 0 deletions Lib/test/test_sys_setprofile.py

Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,24 @@ class A:
# The last c_call is the call to sys.setprofile
self.assertEqual(events, ['c_call', 'c_return', 'c_call'])

class B:
f = classmethod(max)
events = []
sys.setprofile(lambda frame, event, args: events.append(event))
# Not important, we only want to trigger INSTRUMENTED_CALL_KW
B().f(1, key=lambda x: 0)
sys.setprofile(None)
# The last c_call is the call to sys.setprofile
self.assertEqual(
events,
['c_call',
'call', 'return',
'call', 'return',
'c_return',
'c_call'
]
)


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``INSTRUMENTED_CALL_KW`` will expand the method before monitoring to reflect the actual behavior more accurately.

2 changes: 1 addition & 1 deletion Python/bytecodes.c

Original file line number Diff line number Diff line change
Expand Up @@ -4509,8 +4509,8 @@ dummy_func(
macro(INSTRUMENTED_CALL_KW) =
counter/1 +
unused/2 +
_MONITOR_CALL_KW +
_MAYBE_EXPAND_METHOD_KW +
_MONITOR_CALL_KW +
_DO_CALL_KW;

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

52 changes: 25 additions & 27 deletions Python/generated_cases.c.h