Skip to content

Commit e0e303a

Browse files
[3.10] gh-97943: PyFunction_GetAnnotations should return a borrowed reference. (GH-97949) (GH-97989)
gh-97943: PyFunction_GetAnnotations should return a borrowed reference. (GH-97949) (cherry picked from commit 6bfb0be) Co-authored-by: larryhastings <[email protected]>
1 parent bb21bc3 commit e0e303a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Bugfix: :func:`PyFunction_GetAnnotations` should return a borrowed
2+
reference. It was returning a new reference.

Objects/funcobject.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ func_get_annotation_dict(PyFunctionObject *op)
247247
}
248248
Py_SETREF(op->func_annotations, ann_dict);
249249
}
250-
Py_INCREF(op->func_annotations);
251250
assert(PyDict_Check(op->func_annotations));
252251
return op->func_annotations;
253252
}
@@ -474,7 +473,11 @@ func_get_annotations(PyFunctionObject *op, void *Py_UNUSED(ignored))
474473
if (op->func_annotations == NULL)
475474
return NULL;
476475
}
477-
return func_get_annotation_dict(op);
476+
PyObject *d = func_get_annotation_dict(op);
477+
if (d) {
478+
Py_INCREF(d);
479+
}
480+
return d;
478481
}
479482

480483
static int

0 commit comments

Comments
 (0)