Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 93ac78a

Browse filesBrowse files
authored
gh-115058: Add reset_rare_event_counters function in _testinternalcapi (GH-115128)
1 parent 95ebd45 commit 93ac78a
Copy full SHA for 93ac78a

File tree

Expand file treeCollapse file tree

2 files changed

+18
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-0
lines changed

‎Lib/test/test_optimizer.py

Copy file name to clipboardExpand all lines: Lib/test/test_optimizer.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88

99
class TestRareEventCounters(unittest.TestCase):
10+
def setUp(self):
11+
_testinternalcapi.reset_rare_event_counters()
12+
1013
def test_set_class(self):
1114
class A:
1215
pass

‎Modules/_testinternalcapi.c

Copy file name to clipboardExpand all lines: Modules/_testinternalcapi.c
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,20 @@ get_rare_event_counters(PyObject *self, PyObject *type)
16501650
);
16511651
}
16521652

1653+
static PyObject *
1654+
reset_rare_event_counters(PyObject *self, PyObject *Py_UNUSED(type))
1655+
{
1656+
PyInterpreterState *interp = PyInterpreterState_Get();
1657+
1658+
interp->rare_events.set_class = 0;
1659+
interp->rare_events.set_bases = 0;
1660+
interp->rare_events.set_eval_frame_func = 0;
1661+
interp->rare_events.builtin_dict = 0;
1662+
interp->rare_events.func_modification = 0;
1663+
1664+
return Py_None;
1665+
}
1666+
16531667

16541668
#ifdef Py_GIL_DISABLED
16551669
static PyObject *
@@ -1727,6 +1741,7 @@ static PyMethodDef module_functions[] = {
17271741
_TESTINTERNALCAPI_TEST_LONG_NUMBITS_METHODDEF
17281742
{"get_type_module_name", get_type_module_name, METH_O},
17291743
{"get_rare_event_counters", get_rare_event_counters, METH_NOARGS},
1744+
{"reset_rare_event_counters", reset_rare_event_counters, METH_NOARGS},
17301745
#ifdef Py_GIL_DISABLED
17311746
{"py_thread_id", get_py_thread_id, METH_NOARGS},
17321747
#endif

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.