1- import six
2-
31from django .db import models
4-
5- from richenum import RichEnumValue , OrderedRichEnumValue
2+ from richenum import OrderedRichEnumValue
3+ from richenum import RichEnumValue
64
75
86# https://github.com/django/django/blob/64200c14e0072ba0ffef86da46b2ea82fd1e019a/django/db/models/fields/subclassing.py#L31-L44
@@ -61,7 +59,7 @@ def get_prep_value(self, value):
6159 return None
6260 elif isinstance (value , OrderedRichEnumValue ):
6361 return value .index
64- elif isinstance (value , six . integer_types ):
62+ elif isinstance (value , int ):
6563 return value
6664 else :
6765 raise TypeError ('Cannot convert value: %s (%s) to an int.' % (value , type (value )))
@@ -80,7 +78,7 @@ def to_python(self, value):
8078 return None
8179 elif isinstance (value , OrderedRichEnumValue ):
8280 return value
83- elif isinstance (value , six . integer_types ):
81+ elif isinstance (value , int ):
8482 return self .enum .from_index (value )
8583 else :
8684 raise TypeError ('Cannot interpret %s (%s) as an OrderedRichEnumValue.' % (value , type (value )))
@@ -114,19 +112,19 @@ class LaxIndexEnumField(IndexEnumField):
114112 Mainly used to help migrate existing code that uses strings as database values.
115113 '''
116114 def get_prep_value (self , value ):
117- if isinstance (value , six . string_types ):
115+ if isinstance (value , str ):
118116 return self .enum .from_canonical (value ).index
119117 return super (LaxIndexEnumField , self ).get_prep_value (value )
120118
121119 def from_db_value (self , value , expression , connection , * args ):
122120 # context param is deprecated in Django 2.x will be removed in Django 3.x
123121 # having *args allows this code to run in Django 1.x and Django 2.x
124- if isinstance (value , six . string_types ):
122+ if isinstance (value , str ):
125123 return self .enum .from_canonical (value )
126124 return super (LaxIndexEnumField , self ).from_db_value (value , expression , connection , * args )
127125
128126 def to_python (self , value ):
129- if isinstance (value , six . string_types ):
127+ if isinstance (value , str ):
130128 return self .enum .from_canonical (value )
131129 return super (LaxIndexEnumField , self ).to_python (value )
132130
@@ -170,7 +168,7 @@ def get_prep_value(self, value):
170168 return None
171169 elif isinstance (value , RichEnumValue ):
172170 return value .canonical_name
173- elif isinstance (value , six . string_types ):
171+ elif isinstance (value , str ):
174172 return value
175173 else :
176174 raise TypeError ('Cannot convert value: %s (%s) to a string.' % (value , type (value )))
@@ -189,7 +187,7 @@ def to_python(self, value):
189187 return None
190188 elif isinstance (value , RichEnumValue ):
191189 return value
192- elif isinstance (value , six . string_types ):
190+ elif isinstance (value , str ):
193191 return self .enum .from_canonical (value )
194192 else :
195193 raise TypeError ('Cannot interpret %s (%s) as an RichEnumValue.' % (value , type (value )))
0 commit comments