Refs #23919 -- Removed enum ImportError handling for Python 2.

This commit is contained in:
Tim Graham 2017-01-19 13:55:20 -05:00
parent d29fd3f9a6
commit 9ee47ce7b4
3 changed files with 3 additions and 20 deletions

View File

@ -2,6 +2,7 @@ import builtins
import collections import collections
import datetime import datetime
import decimal import decimal
import enum
import functools import functools
import math import math
import types import types
@ -17,12 +18,6 @@ from django.utils.functional import LazyObject, Promise
from django.utils.timezone import utc from django.utils.timezone import utc
from django.utils.version import get_docs_version from django.utils.version import get_docs_version
try:
import enum
except ImportError:
# No support on Python 2 if enum34 isn't installed.
enum = None
class BaseSerializer: class BaseSerializer:
def __init__(self, value): def __init__(self, value):
@ -349,7 +344,7 @@ def serializer_factory(value):
return TupleSerializer(value) return TupleSerializer(value)
if isinstance(value, dict): if isinstance(value, dict):
return DictionarySerializer(value) return DictionarySerializer(value)
if enum and isinstance(value, enum.Enum): if isinstance(value, enum.Enum):
return EnumSerializer(value) return EnumSerializer(value)
if isinstance(value, datetime.datetime): if isinstance(value, datetime.datetime):
return DatetimeSerializer(value) return DatetimeSerializer(value)

View File

@ -13,12 +13,6 @@ from django.utils.inspect import get_func_args
from django.utils.module_loading import module_dir from django.utils.module_loading import module_dir
from django.utils.timezone import now from django.utils.timezone import now
try:
import enum
except ImportError:
# No support on Python 2 if enum34 isn't installed.
enum = None
class SettingsReference(str): class SettingsReference(str):
""" """

View File

@ -1,12 +1,12 @@
import datetime import datetime
import decimal import decimal
import enum
import functools import functools
import math import math
import os import os
import re import re
import sys import sys
import tokenize import tokenize
import unittest
import uuid import uuid
from io import StringIO from io import StringIO
@ -31,11 +31,6 @@ from django.utils.translation import ugettext_lazy as _
from .models import FoodManager, FoodQuerySet from .models import FoodManager, FoodQuerySet
try:
import enum
except ImportError:
enum = None
PY36 = sys.version_info >= (3, 6) PY36 = sys.version_info >= (3, 6)
@ -259,7 +254,6 @@ class WriterTests(SimpleTestCase):
lazy_pattern = SimpleLazyObject(lambda: pattern) lazy_pattern = SimpleLazyObject(lambda: pattern)
self.assertEqual(self.serialize_round_trip(lazy_pattern), pattern) self.assertEqual(self.serialize_round_trip(lazy_pattern), pattern)
@unittest.skipUnless(enum, "enum34 is required on Python 2")
def test_serialize_enums(self): def test_serialize_enums(self):
class TextEnum(enum.Enum): class TextEnum(enum.Enum):
A = 'a-value' A = 'a-value'