1
- from inspect import Parameter , isclass , signature
1
+ from inspect import Parameter , signature
2
2
from typing import Any , Callable , Dict , Generic , Optional , Tuple , Type , cast
3
3
4
4
from apischema .types import AnyType
@@ -32,7 +32,7 @@ def converter_types(
32
32
else :
33
33
parameters = list (signature (converter ).parameters .values ())
34
34
except ValueError : # builtin types
35
- if target is None and isclass (converter ):
35
+ if target is None and is_type (converter ):
36
36
target = cast (Type [Any ], converter )
37
37
if source is None :
38
38
raise TypeError ("Converter source is unknown" ) from None
@@ -51,7 +51,7 @@ def converter_types(
51
51
if source is not None and target is not None :
52
52
return source , target
53
53
types = get_type_hints (converter , None , namespace , include_extras = True )
54
- if not types and isclass (converter ):
54
+ if not types and is_type (converter ):
55
55
types = get_type_hints (
56
56
converter .__new__ , None , namespace , include_extras = True
57
57
) or get_type_hints (
@@ -63,12 +63,12 @@ def converter_types(
63
63
except KeyError :
64
64
raise TypeError ("converter source is unknown" ) from None
65
65
if target is None :
66
- try :
67
- target = types . pop ( "return" )
68
- except KeyError :
69
- if isclass ( converter ) :
70
- target = cast ( Type , converter )
71
- else :
66
+ if is_type ( converter ) :
67
+ target = cast ( Type , converter )
68
+ else :
69
+ try :
70
+ target = types . pop ( "return" )
71
+ except KeyError :
72
72
raise TypeError ("converter target is unknown" ) from None
73
73
return source , target
74
74
0 commit comments