Skip to content

Commit

Permalink
[3.12] gh-116735: Use MISSING for CALL event if argument is absen… (
Browse files Browse the repository at this point in the history
#116873)

[3.12] gh-116735: Use `MISSING` for `CALL` event if argument is absent (GH-116737)
  • Loading branch information
gaogaotiantian committed Mar 19, 2024
1 parent 5da6e30 commit 688623d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Lib/test/test_monitoring.py
Expand Up @@ -1745,9 +1745,10 @@ def test_gh108976(self):
sys.monitoring.set_events(0, 0)

def test_call_function_ex(self):
def f(a, b):
def f(a=1, b=2):
return a + b
args = (1, 2)
empty_args = []

call_data = []
sys.monitoring.use_tool_id(0, "test")
Expand All @@ -1756,5 +1757,7 @@ def f(a, b):
sys.monitoring.register_callback(0, E.CALL, lambda code, offset, callable, arg0: call_data.append((callable, arg0)))
sys.monitoring.set_events(0, E.CALL)
f(*args)
f(*empty_args)
sys.monitoring.set_events(0, 0)
self.assertEqual(call_data[0], (f, 1))
self.assertEqual(call_data[1], (f, sys.monitoring.MISSING))
@@ -0,0 +1 @@
For ``INSTRUMENTED_CALL_FUNCTION_EX``, set ``arg0`` to ``sys.monitoring.MISSING`` instead of ``None`` for :monitoring-event:`CALL` event.
2 changes: 1 addition & 1 deletion Python/bytecodes.c
Expand Up @@ -3209,7 +3209,7 @@ dummy_func(
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_FUNCTION_EX, func);
if (opcode == INSTRUMENTED_CALL_FUNCTION_EX) {
PyObject *arg = PyTuple_GET_SIZE(callargs) > 0 ?
PyTuple_GET_ITEM(callargs, 0) : Py_None;
PyTuple_GET_ITEM(callargs, 0) : &_PyInstrumentation_MISSING;
int err = _Py_call_instrumentation_2args(
tstate, PY_MONITORING_EVENT_CALL,
frame, next_instr-1, func, arg);
Expand Down
2 changes: 1 addition & 1 deletion Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 688623d

Please sign in to comment.