Skip to content

Commit b72ab46

Browse files
cleanup annotationlib use
1 parent 8bf3d3a commit b72ab46

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

elasticsearch/dsl/document_base.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
overload,
3535
)
3636

37+
try:
38+
import annotationlib
39+
except ImportError:
40+
annotationlib = None
41+
3742
try:
3843
from types import UnionType
3944
except ImportError:
@@ -332,21 +337,16 @@ def __init__(self, name: str, bases: Tuple[type, ...], attrs: Dict[str, Any]):
332337
# # ignore attributes
333338
# field10: ClassVar[string] = "a regular class variable"
334339
annotations = attrs.get("__annotations__", {})
335-
if not annotations:
340+
if not annotations and annotationlib:
336341
# 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 {}
342+
annotate = annotationlib.get_annotate_from_class_namespace(attrs)
343+
if annotate:
344+
annotations = (
345+
annotationlib.call_annotate_function(
346+
annotate, format=annotationlib.Format.VALUE
347347
)
348-
except ImportError:
349-
pass
348+
or {}
349+
)
350350
fields = {n for n in attrs if isinstance(attrs[n], Field)}
351351
fields.update(annotations.keys())
352352
field_defaults = {}

0 commit comments

Comments
 (0)