mirror of
https://github.com/python/cpython.git
synced 2024-11-24 10:24:35 +08:00
gh-94808: Cover PyEval_GetFuncName
(#98246)
This commit is contained in:
parent
120b4ab2b6
commit
f01b56c7bd
@ -880,6 +880,21 @@ class CAPITest(unittest.TestCase):
|
||||
_testcapi.clear_managed_dict(c)
|
||||
self.assertEqual(c.__dict__, {})
|
||||
|
||||
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):
|
||||
|
||||
|
@ -5469,6 +5469,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))
|
||||
{
|
||||
@ -5925,6 +5931,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…
Reference in New Issue
Block a user