Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e0e303a

Browse filesBrowse 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 <larry@hastings.org>
1 parent bb21bc3 commit e0e303a
Copy full SHA for e0e303a

File tree

Expand file treeCollapse file tree

2 files changed

+7
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+7
-2
lines changed
+2Lines changed: 2 additions & 0 deletions
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

Copy file name to clipboardExpand all lines: Objects/funcobject.c
+5-2Lines changed: 5 additions & 2 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.