diff --git a/src/drf_yasg/inspectors/field.py b/src/drf_yasg/inspectors/field.py index 27369b3..b4aa73d 100644 --- a/src/drf_yasg/inspectors/field.py +++ b/src/drf_yasg/inspectors/field.py @@ -2,6 +2,7 @@ import datetime import inspect import logging import operator +import sys import uuid from collections import OrderedDict from decimal import Decimal @@ -489,6 +490,9 @@ hinting_type_info = [ (datetime.date, (openapi.TYPE_STRING, openapi.FORMAT_DATE)), ] +if sys.version_info < (3, 0): + hinting_type_info.append((unicode, (openapi.TYPE_STRING, None))) + if typing: def inspect_collection_hint_class(hint_class): args = hint_class.__args__ diff --git a/testproj/users/serializers.py b/testproj/users/serializers.py index 82431a8..f64c1e1 100644 --- a/testproj/users/serializers.py +++ b/testproj/users/serializers.py @@ -1,3 +1,5 @@ +import sys + from django.contrib.auth.models import User from rest_framework import serializers @@ -6,7 +8,10 @@ from snippets.models import Snippet try: import typing # noqa: F401 - from .method_serializers_with_typing import MethodFieldExampleSerializer + if sys.version_info >= (3, 4): + from .method_serializers_with_typing import MethodFieldExampleSerializer + else: + from .method_serializers_without_typing import MethodFieldExampleSerializer except ImportError: from .method_serializers_without_typing import MethodFieldExampleSerializer diff --git a/tests/test_schema_generator.py b/tests/test_schema_generator.py index d11a552..885e5e9 100644 --- a/tests/test_schema_generator.py +++ b/tests/test_schema_generator.py @@ -204,6 +204,7 @@ def test_action_mapping(): @pytest.mark.parametrize('choices, expected_type', [ (['A', 'B'], openapi.TYPE_STRING), + ([u'A', u'B'], openapi.TYPE_STRING), ([123, 456], openapi.TYPE_INTEGER), ([1.2, 3.4], openapi.TYPE_NUMBER), (['A', 456], openapi.TYPE_STRING) diff --git a/tox.ini b/tox.ini index 0511021..58b0851 100644 --- a/tox.ini +++ b/tox.ini @@ -5,6 +5,7 @@ isolated_build_env = .package # https://docs.djangoproject.com/en/dev/faq/install/#what-python-version-can-i-use-with-django envlist = + py27-django111-drf39-typing, py{27,34,35,36}-django111-drf{37,38,39}, py{34,35,36,37}-django20-drf{37,38,39}, py{35,36,37}-django21-drf{37,38,39}, @@ -26,6 +27,8 @@ deps = drf38: djangorestframework>=3.8.0,<3.9 drf39: djangorestframework>=3.9,<3.10 + typing: typing>=3.6.6 + # test with the latest build of django-rest-framework to get early warning of compatibility issues djmaster: https://github.com/encode/django-rest-framework/archive/master.tar.gz djmaster: https://github.com/django/django/archive/master.tar.gz