Skip to content

Commit d5e8d3f

Browse files
ambvmeta-codesync[bot]
authored andcommitted
Sync pre-release CPython main branch from GitHub (2026-06-24)
Summary: Imported python/cpython `3.16.0a0` from upstream rev [`fcda96f`](https://www.github.com/python/cpython/commit/fcda96fbf399d069d11f7e874352ad03273cf0b7) (committed 2026-06-24 02:58:00+00:00). # Commit Info - Base: (`3.16.0a0`) - [`d701f8e`](https://www.github.com/python/cpython/commit/d701f8edbe2884e3e039f3683deabd2d43fa3b2e) (commit date: 2026-06-18 23:29:33+00:00) - Imported: (`3.16.0a0`) - [`fcda96f`](https://www.github.com/python/cpython/commit/fcda96fbf399d069d11f7e874352ad03273cf0b7) (commit date: 2026-06-24 02:58:00+00:00) # Noteworthy file changes - Test files (24 added) - Low-signal files (37 added) (NEWS.d, docs, .github) Complete list of added/removed files: https://www.internalfb.com/intern/everpaste/?color=0&handle=GNow7yCTXdTQNUgGAMQafpDGOmF4br0LAAAz Reviewed By: DinoV Differential Revision: D109526547 fbshipit-source-id: c6740a5a45e2894514d4776272f89786f8555655
1 parent 4e67325 commit d5e8d3f

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

cinderx/PythonLib/cinderx/compiler/pycodegen.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3956,6 +3956,14 @@ def make_type_alias_code_gen(self, node: ast.TypeAlias) -> CodeGenerator312:
39563956
def emit_type_alias_set_func_defaults(self, code_gen: CodeGenerator) -> None:
39573957
pass
39583958

3959+
def make_annotations_code_holder(self, code_gen: CodeGenerator) -> CodeHolder:
3960+
# Hook for the typevar-bound/default and type-alias-value scopes, which
3961+
# carry a synthetic ".format" parameter on 3.14+. Only CPython 3.16
3962+
# renames it back to "format" for these scopes (3.14/3.15 rename it for
3963+
# the __annotate__ scope only), so the default is to emit the code
3964+
# generator unchanged. See CodeGenerator316 for the override.
3965+
return code_gen
3966+
39593967
def visitTypeAlias(self, node: ast.TypeAlias) -> None:
39603968
outer_gen: CodeGenerator312 = self
39613969
if node.type_params:
@@ -3995,7 +4003,7 @@ def visitTypeAlias(self, node: ast.TypeAlias) -> None:
39954003
code_gen.graph.emit_with_loc("RETURN_VALUE", 0, loc=node)
39964004

39974005
outer_gen.set_pos(node)
3998-
outer_gen.emit_closure(code_gen, 0)
4006+
outer_gen.emit_closure(outer_gen.make_annotations_code_holder(code_gen), 0)
39994007
self.emit_type_alias_set_func_defaults(outer_gen)
40004008
outer_gen.emit("BUILD_TUPLE", 3)
40014009
outer_gen.emit_call_intrinsic_1("INTRINSIC_TYPEALIAS")
@@ -5160,7 +5168,7 @@ def compile_type_param_bound_or_default(
51605168

51615169
loc = self.graph.loc
51625170
self.set_pos(bound)
5163-
self.emit_closure(outer_gen, 0)
5171+
self.emit_closure(self.make_annotations_code_holder(outer_gen), 0)
51645172
self.emit("SET_FUNCTION_ATTRIBUTE", MAKE_FUNCTION_DEFAULTS)
51655173
self.set_pos(loc)
51665174

@@ -5944,6 +5952,8 @@ def setup_annotations(
59445952
return outer_gen
59455953

59465954
def leave_annotations(self, gen: CodeGenerator) -> None:
5955+
# The __annotate__ scope's ".format" parameter is renamed back to
5956+
# "format" in every version that defers annotations (3.14+).
59475957
self.emit_closure(AnnotationsCodeHolder(gen), 0)
59485958

59495959
def emit_argannotation(
@@ -6692,6 +6702,13 @@ def emit_opt_function_loop_append(self) -> None:
66926702
class CodeGenerator316(CodeGenerator315):
66936703
flow_graph = PyFlowGraph316
66946704

6705+
def make_annotations_code_holder(self, code_gen: CodeGenerator) -> CodeHolder:
6706+
# 3.16 extended the ".format" -> "format" rename to the
6707+
# typevar-bound/default and type-alias-value scopes (CPython's
6708+
# codegen_rename_annotations_format_param is now also called from
6709+
# codegen_type_param_bound_or_default and codegen_typealias_body).
6710+
return AnnotationsCodeHolder(code_gen)
6711+
66956712
# 3.16 also optimizes frozenset(...) calls (gh-150027).
66966713
SUPPORTED_FUNCTION_CALL_OPS: tuple[str, ...] = (
66976714
CodeGenerator315.SUPPORTED_FUNCTION_CALL_OPS + ("frozenset",)
@@ -6835,7 +6852,10 @@ def getCode(self) -> CodeType:
68356852
# different name (.format) in the symtable; if the name
68366853
# "format" appears in the annotations, it doesn't get clobbered
68376854
# by this name.
6838-
return code.replace(co_varnames=("format",))
6855+
varnames = code.co_varnames
6856+
if varnames and varnames[0] == ".format":
6857+
code = code.replace(co_varnames=("format",) + varnames[1:])
6858+
return code
68396859

68406860

68416861
if __name__ == "__main__":

0 commit comments

Comments
 (0)