| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -307,10 +307,27 @@ def function_without_closure(): ... | |||
| 307 | 307 | _testcapi.function_get_closure(function_without_closure), (1, 2)) | |
| 308 | 308 | self.assertEqual(function_without_closure.__closure__, (1, 2)) | |
| 309 | 309 | ||
| 310 | + def test_function_get_annotations(self): | ||
| 311 | + # Test PyFunction_GetAnnotations() | ||
| 312 | + def normal(): | ||
| 313 | + pass | ||
| 314 | + | ||
| 315 | + def annofn(arg: int) -> str: | ||
| 316 | + return f'arg = {arg}' | ||
| 317 | + | ||
| 318 | + annotations = _testcapi.function_get_annotations(normal) | ||
| 319 | + self.assertIsNone(annotations) | ||
| 320 | + | ||
| 321 | + annotations = _testcapi.function_get_annotations(annofn) | ||
| 322 | + self.assertIsInstance(annotations, dict) | ||
| 323 | + self.assertEqual(annotations, annofn.__annotations__) | ||
| 324 | + | ||
| 325 | + with self.assertRaises(SystemError): | ||
| 326 | + _testcapi.function_get_annotations(None) | ||
| 327 | + | ||
| 310 | 328 | # TODO: test PyFunction_New() | |
| 311 | 329 | # TODO: test PyFunction_NewWithQualName() | |
| 312 | 330 | # TODO: test PyFunction_SetVectorcall() | |
| 313 | - # TODO: test PyFunction_GetAnnotations() | ||
| 314 | 331 | # TODO: test PyFunction_SetAnnotations() | |
| 315 | 332 | # TODO: test PyClassMethod_New() | |
| 316 | 333 | # TODO: test PyStaticMethod_New() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -123,6 +123,13 @@ function_set_closure(PyObject *self, PyObject *args) | |||
| 123 | 123 | } | |
| 124 | 124 | ||
| 125 | 125 | ||
| 126 | + static PyObject * | ||
| 127 | + function_get_annotations(PyObject *self, PyObject *func) | ||
| 128 | + { | ||
| 129 | + return Py_XNewRef(PyFunction_GetAnnotations(func)); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + | ||
| 126 | 133 | static PyMethodDef test_methods[] = { | |
| 127 | 134 | {"function_get_code", function_get_code, METH_O, NULL}, | |
| 128 | 135 | {"function_get_globals", function_get_globals, METH_O, NULL}, | |
@@ -133,6 +140,7 @@ static PyMethodDef test_methods[] = { | |||
| 133 | 140 | {"function_set_kw_defaults", function_set_kw_defaults, METH_VARARGS, NULL}, | |
| 134 | 141 | {"function_get_closure", function_get_closure, METH_O, NULL}, | |
| 135 | 142 | {"function_set_closure", function_set_closure, METH_VARARGS, NULL}, | |
| 143 | + {"function_get_annotations", function_get_annotations, METH_O, NULL}, | ||
| 136 | 144 | {NULL}, | |
| 137 | 145 | }; | |
| 138 | 146 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments