Add style fixes

This commit is contained in:
Konsta Vesterinen
2015-03-01 12:43:09 +02:00
parent 618808c8d3
commit eed9ed0ee3
2 changed files with 11 additions and 5 deletions

View File

@@ -141,8 +141,11 @@ class ChoiceType(types.TypeDecorator, ScalarCoercible):
def __init__(self, choices, impl=None): def __init__(self, choices, impl=None):
self.choices = choices self.choices = choices
if Enum is not None and \ if (
isinstance(choices, type) and issubclass(choices, Enum): Enum is not None and
isinstance(choices, type) and
issubclass(choices, Enum)
):
self.type_impl = EnumTypeImpl(enum_class=choices) self.type_impl = EnumTypeImpl(enum_class=choices)
else: else:
self.type_impl = ChoiceTypeImpl(choices=choices) self.type_impl = ChoiceTypeImpl(choices=choices)
@@ -199,10 +202,12 @@ class EnumTypeImpl(object):
if Enum is None: if Enum is None:
raise ImproperlyConfigured( raise ImproperlyConfigured(
"'enum34' package is required to use 'EnumType' in Python " "'enum34' package is required to use 'EnumType' in Python "
"< 3.4") "< 3.4"
)
if not issubclass(enum_class, Enum): if not issubclass(enum_class, Enum):
raise ImproperlyConfigured( raise ImproperlyConfigured(
"EnumType needs a class of enum defined.") "EnumType needs a class of enum defined."
)
self.enum_class = enum_class self.enum_class = enum_class

View File

@@ -91,7 +91,8 @@ class TestEnumType(TestCase):
id_ = sa.Column(sa.Integer, primary_key=True) id_ = sa.Column(sa.Integer, primary_key=True)
status = sa.Column( status = sa.Column(
ChoiceType(OrderStatus, impl=sa.Integer()), ChoiceType(OrderStatus, impl=sa.Integer()),
default=OrderStatus.unpaid) default=OrderStatus.unpaid
)
def __repr__(self): def __repr__(self):
return 'Order(%r, %r)' % (self.id_, self.status) return 'Order(%r, %r)' % (self.id_, self.status)