summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-11-05 13:32:46 (GMT)
committerGitHub <noreply@github.com>2022-11-05 13:32:46 (GMT)
commit46a493e2db942cada2dd1abd468d52725ceba992 (patch)
tree0961cb66d12caff4336612c5967381ab99ba8fdf
parent573b4518867a3cb3c82aa0edd8e86b073e9ff6da (diff)
downloadcpython-46a493e2db942cada2dd1abd468d52725ceba992.zip
cpython-46a493e2db942cada2dd1abd468d52725ceba992.tar.gz
cpython-46a493e2db942cada2dd1abd468d52725ceba992.tar.bz2
gh-94808: add tests covering `PyEval_GetFuncDesc` function (GH-98300)
(cherry picked from commit b5f711185bd11819566068ddf2a74a1402340e2d) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
-rw-r--r--Lib/test/test_capi.py15
-rw-r--r--Modules/_testcapimodule.c7
2 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index a4d643f..3e65496 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -751,6 +751,21 @@ class CAPITest(unittest.TestCase):
self.assertEqual(_testcapi.eval_get_func_name(sum), "sum") # c function
self.assertEqual(_testcapi.eval_get_func_name(A), "type")
+ def test_eval_get_func_desc(self):
+ def function_example(): ...
+
+ class A:
+ def method_example(self): ...
+
+ self.assertEqual(_testcapi.eval_get_func_desc(function_example),
+ "()")
+ self.assertEqual(_testcapi.eval_get_func_desc(A.method_example),
+ "()")
+ self.assertEqual(_testcapi.eval_get_func_desc(A().method_example),
+ "()")
+ self.assertEqual(_testcapi.eval_get_func_desc(sum), "()") # c function
+ self.assertEqual(_testcapi.eval_get_func_desc(A), " object")
+
def test_function_get_code(self):
import types
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 1c085a4..3ec91bf 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -5976,6 +5976,12 @@ eval_get_func_name(PyObject *self, PyObject *func)
}
static PyObject *
+eval_get_func_desc(PyObject *self, PyObject *func)
+{
+ return PyUnicode_FromString(PyEval_GetFuncDesc(func));
+}
+
+static PyObject *
get_feature_macros(PyObject *self, PyObject *Py_UNUSED(args))
{
PyObject *result = PyDict_New();
@@ -6452,6 +6458,7 @@ static PyMethodDef TestMethods[] = {
{"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},
+ {"eval_get_func_desc", eval_get_func_desc, 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},