Skip to content

Commit 5b4794f

Browse files
committed
Use annotationlib in 3.14
1 parent 0a1f20f commit 5b4794f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

strawberry/types/object_type.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ def _get_interfaces(cls: builtins.type[Any]) -> list[StrawberryObjectDefinition]
4242
return interfaces
4343

4444

45+
def _get_annotations(cls: builtins.type[Any]) -> dict[str, Any]:
46+
try:
47+
import annotationlib
48+
49+
annotations = annotationlib.get_annotations(
50+
cls, format=annotationlib.Format.FORWARDREF
51+
)
52+
except ImportError:
53+
annotations = cls.__dict__.get("__annotations__", {})
54+
55+
return annotations
56+
57+
4558
def _check_field_annotations(cls: builtins.type[Any]) -> None:
4659
"""Are any of the dataclass Fields missing type annotations?
4760
@@ -51,7 +64,8 @@ def _check_field_annotations(cls: builtins.type[Any]) -> None:
5164
5265
https://github.com/python/cpython/blob/6fed3c85402c5ca704eb3f3189ca3f5c67a08d19/Lib/dataclasses.py#L881-L884
5366
"""
54-
cls_annotations = cls.__dict__.get("__annotations__", {})
67+
cls_annotations = _get_annotations(cls)
68+
# TODO: do we need this?
5569
cls.__annotations__ = cls_annotations
5670

5771
for field_name, field_ in cls.__dict__.items():

0 commit comments

Comments
 (0)