fix Optional typing hint for SerializerMethodField (#428)

This commit is contained in:
Étienne Noss
2019-09-29 18:01:28 +02:00
committed by Cristi Vîjdea
parent 8578b93eba
commit 1352c2a23b
2 changed files with 43 additions and 0 deletions
+2
View File
@@ -610,6 +610,8 @@ class SerializerMethodFieldInspector(FieldInspector):
# look for Python 3.5+ style type hinting of the return value
hint_class = inspect_signature(method).return_annotation
if not inspect.isclass(hint_class) and hasattr(hint_class, '__args__'):
hint_class = hint_class.__args__[0]
if inspect.isclass(hint_class) and not issubclass(hint_class, inspect._empty):
type_info = get_basic_type_info_from_hint(hint_class)