Skip to content
Closed
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
17 changes: 16 additions & 1 deletion tensorizer/_crypt/_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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("_"):
Expand Down