11import dataclasses
2- import inspect
32import types
43from enum import Enum
54from inspect import isclass
@@ -38,18 +37,6 @@ def register(cls: Union[type, str], converter: type):
3837register (dict , Dictionary )
3938
4039
41- def resolve (annotation , obj = None ):
42- if isinstance (annotation , str ):
43- log .debug (f"Attempting to eval { annotation !r} using { obj } " )
44- annotation = annotation .replace ("List" , "list" ).replace ("Dict" , "list" )
45- namespace = inspect .getmodule (obj ).__dict__ if obj else None
46- try :
47- return eval (annotation , namespace ) # pylint: disable=eval-used
48- except NameError as e :
49- log .warn (f"Unable to eval: { e } " )
50- return annotation
51-
52-
5340@cached
5441def map_type (cls , * , name : str = "" , item_cls : Optional [type ] = None ):
5542 """Infer the converter type from a dataclass, type, or annotation."""
@@ -66,7 +53,7 @@ def map_type(cls, *, name: str = "", item_cls: Optional[type] = None):
6653 if dataclasses .is_dataclass (cls ):
6754 converters = {}
6855 for field in dataclasses .fields (cls ):
69- converters [field .name ] = map_type (resolve ( field .type ) , name = field .name ) # type: ignore
56+ converters [field .name ] = map_type (field .type , name = field .name ) # type: ignore
7057 converter = Dataclass .of_mappings (cls , converters )
7158 log .debug (f"Mapped { cls !r} to new converter: { converter } " )
7259 return converter
@@ -79,8 +66,6 @@ def map_type(cls, *, name: str = "", item_cls: Optional[type] = None):
7966 converter = converter .as_optional ()
8067 return converter
8168
82- cls = resolve (cls )
83-
8469 if hasattr (cls , "__origin__" ):
8570 converter = None
8671
0 commit comments