gh-97943: PyFunction_GetAnnotations should return a borrowed reference. (GH-97949)

(cherry picked from commit 6bfb0be804)

Co-authored-by: larryhastings <larry@hastings.org>
This commit is contained in:
Miss Islington (bot) 2022-10-06 13:03:32 -07:00 committed by GitHub
parent 4aa2ebc01e
commit 33cf0a604c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -0,0 +1,2 @@
Bugfix: :func:`PyFunction_GetAnnotations` should return a borrowed
reference. It was returning a new reference.

View File

@ -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