#4067·Nuitka

Python 3.14: 为编译的类 __annotate__ 关闭了局部变量时,annotationlib.call_annotate_function(FORWARDREF) 失败

作者: KRRT7创建于 2026年9月29日更新于 2026年9月29日

import annotationlib import sys

def make(): from typing import Any class C: x: Any = None return C C = make() print(sys.version.split()[0], "compiled" if "compiled" in globals() else "interpreted") print(annotationlib.call_annotate_function(C.annotate, annotationlib.Format.FORWARDREF))

sh 3.14.7 interpreted {'x': typing.Any} 3.14.7 compiled Traceback (most recent call last): File "repro.py", line 20, in print(annotationlib.call_annotate_function(C.annotate, annotationlib.Format.FORWARDREF)) File ".../lib/python3.14/annotationlib.py", line 810, in call_annotate_function closure, cell_dict = _build_closure( File ".../lib/python3.14/annotationlib.py", line 879, in _build_closure for name, cell in zip(annotate.code.co_freevars, annotate.closure, strict=True): ValueError: zip() argument 2 is longer than