Skip to content

Commit

Permalink
pythongh-97943: PyFunction_GetAnnotations should return a borrowed re…
Browse files Browse the repository at this point in the history
…ference. (pythonGH-97949)

(cherry picked from commit 6bfb0be)

Co-authored-by: larryhastings <larry@hastings.org>
  • Loading branch information
larryhastings authored and miss-islington committed Oct 6, 2022
1 parent 3d89ac2 commit 787cc60
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Bugfix: :func:`PyFunction_GetAnnotations` should return a borrowed
reference. It was returning a new reference.
7 changes: 5 additions & 2 deletions Objects/funcobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,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;
}
Expand Down Expand Up @@ -474,7 +473,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
Expand Down

0 comments on commit 787cc60

Please sign in to comment.