diff options
Diffstat (limited to 'Objects/funcobject.c')
-rw-r--r-- | Objects/funcobject.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Objects/funcobject.c b/Objects/funcobject.c index 9b4302a13c..e7961b3e6e 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -424,6 +424,25 @@ func_get_annotations(PyFunctionObject *op, void *Py_UNUSED(ignored)) if (op->func_annotations == NULL) return NULL; } + if (PyTuple_CheckExact(op->func_annotations)) { + PyObject *ann_tuple = op->func_annotations; + PyObject *ann_dict = PyDict_New(); + if (ann_dict == NULL) { + return NULL; + } + + assert(PyTuple_GET_SIZE(ann_tuple) % 2 == 0); + + for (Py_ssize_t i = 0; i < PyTuple_GET_SIZE(ann_tuple); i += 2) { + int err = PyDict_SetItem(ann_dict, + PyTuple_GET_ITEM(ann_tuple, i), + PyTuple_GET_ITEM(ann_tuple, i + 1)); + + if (err < 0) + return NULL; + } + Py_SETREF(op->func_annotations, ann_dict); + } Py_INCREF(op->func_annotations); return op->func_annotations; } |