diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-10-06 20:03:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-06 20:03:32 (GMT) |
commit | 33cf0a604c111fc291dffaa0fb104336cb7d0add (patch) | |
tree | bcf8f995c5761d8c0a677f0b0a358bc1eb28bb5b | |
parent | 4aa2ebc01e63cf53c2c152eb4e0ea82bc932c3d5 (diff) | |
download | cpython-33cf0a604c111fc291dffaa0fb104336cb7d0add.zip cpython-33cf0a604c111fc291dffaa0fb104336cb7d0add.tar.gz cpython-33cf0a604c111fc291dffaa0fb104336cb7d0add.tar.bz2 |
gh-97943: PyFunction_GetAnnotations should return a borrowed reference. (GH-97949)
(cherry picked from commit 6bfb0be80486c614cd60dce44c9fe7b3e6c76e3b)
Co-authored-by: larryhastings <larry@hastings.org>
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2022-10-05-17-02-22.gh-issue-97943.LYAWlE.rst | 2 | ||||
-rw-r--r-- | Objects/funcobject.c | 7 |
2 files changed, 7 insertions, 2 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-10-05-17-02-22.gh-issue-97943.LYAWlE.rst b/Misc/NEWS.d/next/Core and Builtins/2022-10-05-17-02-22.gh-issue-97943.LYAWlE.rst new file mode 100644 index 0000000..9b4a421 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-10-05-17-02-22.gh-issue-97943.LYAWlE.rst @@ -0,0 +1,2 @@ +Bugfix: :func:`PyFunction_GetAnnotations` should return a borrowed +reference. It was returning a new reference. diff --git a/Objects/funcobject.c b/Objects/funcobject.c index 32b4155..6307463 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -300,7 +300,6 @@ func_get_annotation_dict(PyFunctionObject *op) } Py_SETREF(op->func_annotations, ann_dict); } - Py_INCREF(op->func_annotations); assert(PyDict_Check(op->func_annotations)); return op->func_annotations; } @@ -532,7 +531,11 @@ func_get_annotations(PyFunctionObject *op, void *Py_UNUSED(ignored)) if (op->func_annotations == NULL) return NULL; } - return func_get_annotation_dict(op); + PyObject *d = func_get_annotation_dict(op); + if (d) { + Py_INCREF(d); + } + return d; } static int |