There was an error while loading. Please reload this page.
1 parent 23e83a8 commit 6bfb0beCopy full SHA for 6bfb0be
2 files changed
Misc/NEWS.d/next/Core and Builtins/2022-10-05-17-02-22.gh-issue-97943.LYAWlE.rst
@@ -0,0 +1,2 @@
1
+Bugfix: :func:`PyFunction_GetAnnotations` should return a borrowed
2
+reference. It was returning a new reference.
Objects/funcobject.c
@@ -311,7 +311,6 @@ func_get_annotation_dict(PyFunctionObject *op)
311
}
312
Py_SETREF(op->func_annotations, ann_dict);
313
314
- Py_INCREF(op->func_annotations);
315
assert(PyDict_Check(op->func_annotations));
316
return op->func_annotations;
317
@@ -543,7 +542,11 @@ func_get_annotations(PyFunctionObject *op, void *Py_UNUSED(ignored))
543
542
if (op->func_annotations == NULL)
544
return NULL;
545
546
- return func_get_annotation_dict(op);
+ PyObject *d = func_get_annotation_dict(op);
+ if (d) {
547
+ Py_INCREF(d);
548
+ }
549
+ return d;
550
551
552
static int
0 commit comments