Skip to content

Commit e6f1adf

Browse files
committed
fix bug and refleak
1 parent f29b8b9 commit e6f1adf

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Lib/test/test_type_annotations.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,9 @@ def test_complex_comprehension_inlining_exec(self):
838838

839839
def test_annotate_qualname(self):
840840
code = """
841-
def f() -> None: pass
841+
def f() -> None:
842+
def nested() -> None: pass
843+
return nested
842844
class Outer:
843845
x: int
844846
def method(self, x: int):
@@ -848,4 +850,5 @@ def method(self, x: int):
848850
method = ns["Outer"].method
849851
self.assertEqual(method.__annotate__.__qualname__, "Outer.method.__annotate__")
850852
self.assertEqual(ns["f"].__annotate__.__qualname__, "f.__annotate__")
853+
self.assertEqual(ns["f"]().__annotate__.__qualname__, "f.<locals>.nested.__annotate__")
851854
self.assertEqual(ns["Outer"].__annotate__.__qualname__, "Outer.__annotate__")

Python/compile.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,11 @@ compiler_set_qualname(compiler *c)
290290
}
291291
}
292292
if (u->u_ste->ste_function_name != NULL) {
293+
PyObject *tmp = base;
293294
base = PyUnicode_FromFormat("%U.%U",
294-
parent->u_metadata.u_qualname,
295+
base,
295296
u->u_ste->ste_function_name);
297+
Py_DECREF(tmp);
296298
if (base == NULL) {
297299
return ERROR;
298300
}

0 commit comments

Comments
 (0)