Skip to content

Commit 5c9d449

Browse files
authored
GH-111339: Change valid property of executors to is_valid() method (GH-111350)
1 parent 78e6d72 commit 5c9d449

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

Lib/test/test_capi/test_misc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,19 +2479,19 @@ def f{n}():
24792479
# Set things up so each executor depends on the objects
24802480
# with an equal or lower index.
24812481
for i, exe in enumerate(executors):
2482-
self.assertTrue(exe.valid)
2482+
self.assertTrue(exe.is_valid())
24832483
for obj in objects[:i+1]:
24842484
_testinternalcapi.add_executor_dependency(exe, obj)
2485-
self.assertTrue(exe.valid)
2485+
self.assertTrue(exe.is_valid())
24862486
# Assert that the correct executors are invalidated
24872487
# and check that nothing crashes when we invalidate
24882488
# an executor mutliple times.
24892489
for i in (4,3,2,1,0):
24902490
_testinternalcapi.invalidate_executors(objects[i])
24912491
for exe in executors[i:]:
2492-
self.assertFalse(exe.valid)
2492+
self.assertFalse(exe.is_valid())
24932493
for exe in executors[:i]:
2494-
self.assertTrue(exe.valid)
2494+
self.assertTrue(exe.is_valid())
24952495

24962496
def test_uop_optimizer_invalidation(self):
24972497
# Generate a new function at each call
@@ -2506,9 +2506,9 @@ def f():
25062506
with temporary_optimizer(opt):
25072507
f()
25082508
exe = get_first_executor(f)
2509-
self.assertTrue(exe.valid)
2509+
self.assertTrue(exe.is_valid())
25102510
_testinternalcapi.invalidate_executors(f.__code__)
2511-
self.assertFalse(exe.valid)
2511+
self.assertFalse(exe.is_valid())
25122512

25132513
class TestUops(unittest.TestCase):
25142514

Python/optimizer.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,15 @@ counter_dealloc(_PyCounterExecutorObject *self) {
225225
PyObject_Free(self);
226226
}
227227

228-
static PyMemberDef counter_members[] = {
229-
{ "valid", Py_T_UBYTE, offsetof(_PyCounterExecutorObject, executor.vm_data.valid), Py_READONLY, "is valid?" },
230-
{ NULL }
228+
static PyObject *
229+
is_valid(PyObject *self, PyObject *Py_UNUSED(ignored))
230+
{
231+
return PyBool_FromLong(((_PyExecutorObject *)self)->vm_data.valid);
232+
}
233+
234+
static PyMethodDef executor_methods[] = {
235+
{ "is_valid", is_valid, METH_NOARGS, NULL },
236+
{ NULL, NULL },
231237
};
232238

233239
static PyTypeObject CounterExecutor_Type = {
@@ -237,7 +243,7 @@ static PyTypeObject CounterExecutor_Type = {
237243
.tp_itemsize = 0,
238244
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
239245
.tp_dealloc = (destructor)counter_dealloc,
240-
.tp_members = counter_members,
246+
.tp_methods = executor_methods,
241247
};
242248

243249
static _PyInterpreterFrame *
@@ -280,7 +286,7 @@ counter_get_counter(PyObject *self, PyObject *args)
280286
return PyLong_FromLongLong(((_PyCounterOptimizerObject *)self)->count);
281287
}
282288

283-
static PyMethodDef counter_methods[] = {
289+
static PyMethodDef counter_optimizer_methods[] = {
284290
{ "get_count", counter_get_counter, METH_NOARGS, NULL },
285291
{ NULL, NULL },
286292
};
@@ -291,7 +297,7 @@ static PyTypeObject CounterOptimizer_Type = {
291297
.tp_basicsize = sizeof(_PyCounterOptimizerObject),
292298
.tp_itemsize = 0,
293299
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
294-
.tp_methods = counter_methods,
300+
.tp_methods = counter_optimizer_methods,
295301
.tp_dealloc = (destructor)PyObject_Del,
296302
};
297303

@@ -369,12 +375,6 @@ PySequenceMethods uop_as_sequence = {
369375
.sq_item = (ssizeargfunc)uop_item,
370376
};
371377

372-
373-
static PyMemberDef uop_members[] = {
374-
{ "valid", Py_T_UBYTE, offsetof(_PyUOpExecutorObject, base.vm_data.valid), Py_READONLY, "is valid?" },
375-
{ NULL }
376-
};
377-
378378
static PyTypeObject UOpExecutor_Type = {
379379
PyVarObject_HEAD_INIT(&PyType_Type, 0)
380380
.tp_name = "uop_executor",
@@ -383,7 +383,7 @@ static PyTypeObject UOpExecutor_Type = {
383383
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
384384
.tp_dealloc = (destructor)uop_dealloc,
385385
.tp_as_sequence = &uop_as_sequence,
386-
.tp_members = uop_members,
386+
.tp_methods = executor_methods,
387387
};
388388

389389
static int

0 commit comments

Comments
 (0)