From 9ee47ce7b45eaf1a9313f8c1680649a68cbb5681 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 19 Jan 2017 13:55:20 -0500 Subject: [PATCH] Refs #23919 -- Removed enum ImportError handling for Python 2. --- django/db/migrations/serializer.py | 9 ++------- django/db/migrations/writer.py | 6 ------ tests/migrations/test_writer.py | 8 +------- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/django/db/migrations/serializer.py b/django/db/migrations/serializer.py index 9e5d74afb9..eff3ebe0d7 100644 --- a/django/db/migrations/serializer.py +++ b/django/db/migrations/serializer.py @@ -2,6 +2,7 @@ import builtins import collections import datetime import decimal +import enum import functools import math import types @@ -17,12 +18,6 @@ from django.utils.functional import LazyObject, Promise from django.utils.timezone import utc 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: def __init__(self, value): @@ -349,7 +344,7 @@ def serializer_factory(value): return TupleSerializer(value) if isinstance(value, dict): return DictionarySerializer(value) - if enum and isinstance(value, enum.Enum): + if isinstance(value, enum.Enum): return EnumSerializer(value) if isinstance(value, datetime.datetime): return DatetimeSerializer(value) diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py index be0fece25e..5a3378fe4b 100644 --- a/django/db/migrations/writer.py +++ b/django/db/migrations/writer.py @@ -13,12 +13,6 @@ from django.utils.inspect import get_func_args from django.utils.module_loading import module_dir 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): """ diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index ab6280856a..a51842e02d 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -1,12 +1,12 @@ import datetime import decimal +import enum import functools import math import os import re import sys import tokenize -import unittest import uuid from io import StringIO @@ -31,11 +31,6 @@ from django.utils.translation import ugettext_lazy as _ from .models import FoodManager, FoodQuerySet -try: - import enum -except ImportError: - enum = None - PY36 = sys.version_info >= (3, 6) @@ -259,7 +254,6 @@ class WriterTests(SimpleTestCase): lazy_pattern = SimpleLazyObject(lambda: pattern) self.assertEqual(self.serialize_round_trip(lazy_pattern), pattern) - @unittest.skipUnless(enum, "enum34 is required on Python 2") def test_serialize_enums(self): class TextEnum(enum.Enum): A = 'a-value'