Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Lib/test/test_type_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,23 @@ def test_complex_comprehension_inlining_exec(self):
lamb = list(genexp)[0]
self.assertEqual(lamb(), 42)

def test_annotate_qualname(self):
code = """
def f() -> None:
def nested() -> None: pass
return nested
class Outer:
x: int
def method(self, x: int):
pass
"""
ns = run_code(code)
method = ns["Outer"].method
self.assertEqual(ns["f"].__annotate__.__qualname__, "f.__annotate__")
self.assertEqual(ns["f"]().__annotate__.__qualname__, "f.<locals>.nested.__annotate__")
self.assertEqual(method.__annotate__.__qualname__, "Outer.method.__annotate__")
self.assertEqual(ns["Outer"].__annotate__.__qualname__, "Outer.__annotate__")

# gh-138349
def test_module_level_annotation_plus_listcomp(self):
cases = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix the ``__qualname__`` attribute of ``__annotate__`` functions on
functions.
7 changes: 7 additions & 0 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -4970,6 +4970,13 @@ dummy_func(
PyObject **ptr = (PyObject **)(((char *)func) + offset);
assert(*ptr == NULL);
*ptr = attr;
if (oparg == MAKE_FUNCTION_ANNOTATE && PyFunction_Check(attr)) {
// gh-137814: Fix the qualname of __annotate__ functions
PyFunctionObject *func_obj = (PyFunctionObject *)attr;
PyObject *fixed_qualname = PyUnicode_FromFormat("%U.__annotate__", ((PyFunctionObject *)func)->func_qualname);
ERROR_IF(fixed_qualname == NULL);
Py_SETREF(func_obj->func_qualname, fixed_qualname);
}
}

inst(RETURN_GENERATOR, (-- res)) {
Expand Down
16 changes: 16 additions & 0 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading