There was an error while loading. Please reload this page.
1 parent 4aa2ebc commit 33cf0a6Copy full SHA for 33cf0a6
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
@@ -300,7 +300,6 @@ func_get_annotation_dict(PyFunctionObject *op)
300
}
301
Py_SETREF(op->func_annotations, ann_dict);
302
303
- Py_INCREF(op->func_annotations);
304
assert(PyDict_Check(op->func_annotations));
305
return op->func_annotations;
306
@@ -532,7 +531,11 @@ func_get_annotations(PyFunctionObject *op, void *Py_UNUSED(ignored))
532
531
if (op->func_annotations == NULL)
533
return NULL;
534
535
- return func_get_annotation_dict(op);
+ PyObject *d = func_get_annotation_dict(op);
+ if (d) {
536
+ Py_INCREF(d);
537
+ }
538
+ return d;
539
540
541
static int
0 commit comments