Fix unicode attribute error if typing installed on py2.7 (#363)

master
elliott-omosheye 2019-06-12 22:51:47 +01:00 committed by Cristi Vîjdea
parent 91ef83e830
commit b5aba7243d
4 changed files with 14 additions and 1 deletions

View File

@ -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__

View File

@ -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
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

View File

@ -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)

View File

@ -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