Skip to content

Commit 59e30f4

Browse files
gh-116735: Use MISSING for CALL event if argument is absent (GH-116737)
1 parent d180b50 commit 59e30f4

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

Lib/test/test_monitoring.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1808,9 +1808,10 @@ def test_gh108976(self):
18081808
sys.monitoring.set_events(0, 0)
18091809

18101810
def test_call_function_ex(self):
1811-
def f(a, b):
1811+
def f(a=1, b=2):
18121812
return a + b
18131813
args = (1, 2)
1814+
empty_args = []
18141815

18151816
call_data = []
18161817
sys.monitoring.use_tool_id(0, "test")
@@ -1819,8 +1820,10 @@ def f(a, b):
18191820
sys.monitoring.register_callback(0, E.CALL, lambda code, offset, callable, arg0: call_data.append((callable, arg0)))
18201821
sys.monitoring.set_events(0, E.CALL)
18211822
f(*args)
1823+
f(*empty_args)
18221824
sys.monitoring.set_events(0, 0)
18231825
self.assertEqual(call_data[0], (f, 1))
1826+
self.assertEqual(call_data[1], (f, sys.monitoring.MISSING))
18241827

18251828

18261829
class TestOptimizer(MonitoringTestBase, unittest.TestCase):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
For ``INSTRUMENTED_CALL_FUNCTION_EX``, set ``arg0`` to ``sys.monitoring.MISSING`` instead of ``None`` for :monitoring-event:`CALL` event.

Python/bytecodes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3774,7 +3774,7 @@ dummy_func(
37743774
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_FUNCTION_EX, func);
37753775
if (opcode == INSTRUMENTED_CALL_FUNCTION_EX) {
37763776
PyObject *arg = PyTuple_GET_SIZE(callargs) > 0 ?
3777-
PyTuple_GET_ITEM(callargs, 0) : Py_None;
3777+
PyTuple_GET_ITEM(callargs, 0) : &_PyInstrumentation_MISSING;
37783778
int err = _Py_call_instrumentation_2args(
37793779
tstate, PY_MONITORING_EVENT_CALL,
37803780
frame, this_instr, func, arg);

Python/generated_cases.c.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)