From 02b884891229c7a2a5cf8f02a708e466bed924fa Mon Sep 17 00:00:00 2001 From: Julian Bez Date: Mon, 3 Sep 2018 12:10:58 +0200 Subject: [PATCH] Fix error when using typing classes (#195) Closes #195. --- src/drf_yasg/inspectors/field.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/drf_yasg/inspectors/field.py b/src/drf_yasg/inspectors/field.py index a7798a2..6d97a47 100644 --- a/src/drf_yasg/inspectors/field.py +++ b/src/drf_yasg/inspectors/field.py @@ -5,6 +5,7 @@ import operator import uuid from collections import OrderedDict from decimal import Decimal +from inspect import isclass from django.core import validators from django.db import models @@ -511,7 +512,9 @@ class SerializerMethodFieldInspector(FieldInspector): # look for Python 3.5+ style type hinting of the return value hint_class = inspect.signature(method).return_annotation - if not issubclass(hint_class, inspect._empty): + if not isclass(hint_class) and hasattr(hint_class, '__args__'): + hint_class = hint_class.__args__[0] + if isclass(hint_class) and not issubclass(hint_class, inspect._empty): type_info = get_basic_type_info_from_hint(hint_class) if type_info is not None: