From 0c03cc48bef4ed712fb285ea6dddc6e441c9a934 Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Wed, 15 Apr 2026 23:51:02 -0700 Subject: [PATCH] Fix Constants() to work with Python 3.14 annotations. In Python 3.14 (PEP 649), annotations are lazily evaluated and stored as ``__annotate_func__`` instead of ``__annotations__``. --- tensorizer/_crypt/_encryption.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tensorizer/_crypt/_encryption.py b/tensorizer/_crypt/_encryption.py index dc519a44..37a616ab 100644 --- a/tensorizer/_crypt/_encryption.py +++ b/tensorizer/_crypt/_encryption.py @@ -346,6 +346,21 @@ def init_sodium_memzero(): sodium_memzero = init_sodium_memzero() +def _pop_annotations(dct: dict) -> dict: + """Extract annotations from a metaclass namespace dict. + + In Python 3.14+ (PEP 649), annotations are lazily evaluated and stored + as ``__annotate_func__`` instead of ``__annotations__``. + """ + annotations = dct.pop("__annotations__", None) + if annotations is not None: + return annotations + annotate_func = dct.get("__annotate_func__") + if annotate_func is not None: + return annotate_func(1) + return {} + + class Constants(type): @staticmethod def _get_constant(name, typ) -> int: @@ -355,7 +370,7 @@ def _get_constant(name, typ) -> int: return getter() def __new__(cls, name: str, bases: tuple, dct: dict) -> NamedTuple: - annotations = dct.pop("__annotations__", {}) + annotations = _pop_annotations(dct) entries = {} for constant_name, constant_type in dct.items(): if constant_name.startswith("_"):