Skip to content

Commit 971d294

Browse files
committed
Add test for tp_descr_get called with None
1 parent d4f0d73 commit 971d294

File tree

1 file changed

+29
-0
lines changed
  • graalpython/com.oracle.graal.python.test/src/tests/cpyext

1 file changed

+29
-0
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_object.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,35 @@ class TestCustomBasicsizeSubclass(TestCustomBasicsize):
401401
actual_basicsize = TestCustomBasicsizeSubclass.__basicsize__
402402
assert expected_basicsize == actual_basicsize, "expected = %s, actual = %s" % (expected_basicsize, actual_basicsize)
403403

404+
def test_descrget(self):
405+
TestDescrGet = CPyExtType(
406+
"TestDescrGet",
407+
'''
408+
PyObject* testdescr_get(PyObject* self, PyObject* obj, PyObject* type) {
409+
if (obj == NULL) {
410+
obj = Py_Ellipsis;
411+
}
412+
if (type == NULL) {
413+
type = Py_Ellipsis;
414+
}
415+
return Py_BuildValue("OOO", self, obj, type);
416+
}
417+
''',
418+
tp_descr_get="(descrgetfunc) testdescr_get",
419+
)
420+
421+
descr = TestDescrGet()
422+
423+
class Test:
424+
getter = descr
425+
426+
obj = Test()
427+
# Using Ellipsis as a placeholder for C NULL
428+
assert obj.getter == (descr, obj, Test)
429+
assert Test.getter == (descr, ..., Test)
430+
assert descr.__get__(1, int) == (descr, 1, int)
431+
assert descr.__get__(1, None) == (descr, 1, ...)
432+
assert descr.__get__(None, int) == (descr, ..., int)
404433

405434
def test_descrset(self):
406435
TestDescrSet = CPyExtType("TestDescrSet",

0 commit comments

Comments
 (0)