File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff 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+
4558def _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 ():
You can’t perform that action at this time.
0 commit comments