[Python-checkins] gh-94808: add tests covering `PyEval_GetFuncDesc` function (GH-98300)

iritkatriel webhook-mailer at python.org
Sat Nov 5 09:08:05 EDT 2022


https://github.com/python/cpython/commit/b5f711185bd11819566068ddf2a74a1402340e2d
commit: b5f711185bd11819566068ddf2a74a1402340e2d
branch: main
author: Nikita Sobolev <mail at sobolevn.me>
committer: iritkatriel <1055913+iritkatriel at users.noreply.github.com>
date: 2022-11-05T13:07:59Z
summary:

gh-94808: add tests covering `PyEval_GetFuncDesc` function (GH-98300)

files:
M Lib/test/test_capi.py
M Modules/_testcapimodule.c

diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 49f207ed953c..07f27ccf07bf 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -907,6 +907,21 @@ def method_example(self): ...
         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 19ceb108ed4e..269642e4df09 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -5579,6 +5579,12 @@ eval_get_func_name(PyObject *self, PyObject *func)
     return PyUnicode_FromString(PyEval_GetFuncName(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))
 {
@@ -6226,6 +6232,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},



More information about the Python-checkins mailing list