gh-97943: PyFunction_GetAnnotations should return a borrowed reference. (GH-97949)
(cherry picked from commit
6bfb0be80486c614cd60dce44c9fe7b3e6c76e3b)
Co-authored-by: larryhastings <larry@hastings.org>
--- /dev/null
+Bugfix: :func:`PyFunction_GetAnnotations` should return a borrowed
+reference. It was returning a new reference.
}
Py_SETREF(op->func_annotations, ann_dict);
}
- Py_INCREF(op->func_annotations);
assert(PyDict_Check(op->func_annotations));
return op->func_annotations;
}
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