File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 2626import re
2727import sys
2828import types
29+ import typing
2930import uuid
3031from enum import StrEnum
3132from typing import (
@@ -1280,7 +1281,7 @@ def handles_type(cls, py_type: Type) -> bool:
12801281 # If we are subclassing a string, used the "named string" approach
12811282 and (inspect .isclass (py_type ) and not issubclass (py_type , str ))
12821283 # and any other class with typed annotations
1283- and bool ( get_type_hints ( py_type ) )
1284+ and has_annotations ( py_type )
12841285 )
12851286
12861287 def __init__ (
@@ -1453,3 +1454,13 @@ def _type_from_annotated(py_type: Type) -> Type:
14531454 return args [0 ]
14541455 else :
14551456 return py_type
1457+
1458+
1459+ def has_annotations (py_type : Type ) -> bool :
1460+ """Checks if a type has annotations"""
1461+ py_type = _type_from_annotated (py_type )
1462+ try :
1463+ return bool (typing .get_type_hints (py_type ))
1464+ except Exception :
1465+ pass
1466+ return hasattr (py_type , "__annotations__" )
You can’t perform that action at this time.
0 commit comments