@@ -15,9 +15,11 @@ class TypeParsingError(ValueError):
15
15
"""
16
16
17
17
18
- def _parse_complex_type (param_type : Union [type_ext .Type , _GenericAlias ]) -> str :
18
+ def _parse_standard_type (param_type : Union [type_ext .Type , _GenericAlias ]) -> str :
19
19
"""
20
- Generates string representation of a complex type from `typing` or `typing_extensions` module.
20
+ Generates string representation of a data type (or alias) being neither custom class or string.
21
+ This function is primarily intended to parse types from consecutive modules:
22
+ `builtins` (>= Python 3.9), `typing` and `typing_extensions`.
21
23
22
24
Args:
23
25
param_type: type or type alias.
@@ -78,9 +80,16 @@ def parse_param_type(param_type: Union[type_ext.Type, _GenericAlias, str]) -> st
78
80
if isinstance (param_type , str ):
79
81
return f"'{ param_type } '"
80
82
81
- if param_type .__module__ in ["typing" , "typing_extensions" ]:
82
- return _parse_complex_type (param_type )
83
+ if param_type .__module__ in ["builtins" , " typing" , "typing_extensions" ]:
84
+ return _parse_standard_type (param_type )
83
85
86
+ # TODO add explicit support Generic types,
87
+ # although they should be already handled okay by _parse_standard_type()
88
+
89
+ # TODO test on various different Python versions > 3.8
90
+
91
+ # fallback, at the moment we expect this to be called only for type aliases
92
+ # note that in Python 3.12+ there exists typing.TypeAliasType that can be checked with isinstance()
84
93
return str (param_type )
85
94
86
95
0 commit comments