mirror of
https://github.com/python/cpython.git
synced 2025-10-03 21:55:41 +00:00
[3.11] gh-94808: Cover PyEval_GetFuncName
(GH-98246). (#98283)
(cherry picked from commit f01b56c7bd
)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
parent
099620b0ce
commit
93d0d9cfdd
2 changed files with 22 additions and 0 deletions
|
@ -724,6 +724,21 @@ class CAPITest(unittest.TestCase):
|
|||
with self.subTest(name=name):
|
||||
self.assertTrue(hasattr(ctypes.pythonapi, name))
|
||||
|
||||
def test_eval_get_func_name(self):
|
||||
def function_example(): ...
|
||||
|
||||
class A:
|
||||
def method_example(self): ...
|
||||
|
||||
self.assertEqual(_testcapi.eval_get_func_name(function_example),
|
||||
"function_example")
|
||||
self.assertEqual(_testcapi.eval_get_func_name(A.method_example),
|
||||
"method_example")
|
||||
self.assertEqual(_testcapi.eval_get_func_name(A().method_example),
|
||||
"method_example")
|
||||
self.assertEqual(_testcapi.eval_get_func_name(sum), "sum") # c function
|
||||
self.assertEqual(_testcapi.eval_get_func_name(A), "type")
|
||||
|
||||
|
||||
class TestPendingCalls(unittest.TestCase):
|
||||
|
||||
|
|
|
@ -5935,6 +5935,12 @@ frame_getlasti(PyObject *self, PyObject *frame)
|
|||
return PyLong_FromLong(lasti);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
eval_get_func_name(PyObject *self, PyObject *func)
|
||||
{
|
||||
return PyUnicode_FromString(PyEval_GetFuncName(func));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
get_feature_macros(PyObject *self, PyObject *Py_UNUSED(args))
|
||||
{
|
||||
|
@ -6372,6 +6378,7 @@ static PyMethodDef TestMethods[] = {
|
|||
{"frame_getgenerator", frame_getgenerator, METH_O, NULL},
|
||||
{"frame_getbuiltins", frame_getbuiltins, METH_O, NULL},
|
||||
{"frame_getlasti", frame_getlasti, METH_O, NULL},
|
||||
{"eval_get_func_name", eval_get_func_name, METH_O, NULL},
|
||||
{"get_feature_macros", get_feature_macros, METH_NOARGS, NULL},
|
||||
{"test_code_api", test_code_api, METH_NOARGS, NULL},
|
||||
{"settrace_to_record", settrace_to_record, METH_O, NULL},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue