Skip to content

Commit 5e232b6

Browse files
Support Python 3.14 __annotate_func__
1 parent b4a01f7 commit 5e232b6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

elasticsearch/dsl/document_base.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,21 @@ def __init__(self, name: str, bases: Tuple[type, ...], attrs: Dict[str, Any]):
332332
# # ignore attributes
333333
# field10: ClassVar[string] = "a regular class variable"
334334
annotations = attrs.get("__annotations__", {})
335+
if not annotations:
336+
# Python 3.14+ uses annotationlib
337+
try:
338+
import annotationlib
339+
340+
annotate = annotationlib.get_annotate_from_class_namespace(attrs)
341+
if annotate:
342+
annotations = (
343+
annotationlib.call_annotate_function(
344+
annotate, format=annotationlib.Format.VALUE
345+
)
346+
or {}
347+
)
348+
except ImportError:
349+
pass
335350
fields = {n for n in attrs if isinstance(attrs[n], Field)}
336351
fields.update(annotations.keys())
337352
field_defaults = {}

0 commit comments

Comments
 (0)