mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2024-11-22 09:06:41 +03:00
Simplify conversion of int and float fields
This commit is contained in:
parent
4efdcda97b
commit
a3bd212133
|
@ -108,11 +108,10 @@ class DateTimeField(Field):
|
|||
class BaseIntField(Field):
|
||||
|
||||
def to_python(self, value):
|
||||
if isinstance(value, int):
|
||||
return value
|
||||
if isinstance(value, basestring):
|
||||
try:
|
||||
return int(value)
|
||||
raise ValueError('Invalid value for %s - %r' % (self.__class__.__name__, value))
|
||||
except:
|
||||
raise ValueError('Invalid value for %s - %r' % (self.__class__.__name__, value))
|
||||
|
||||
def validate(self, value):
|
||||
self._range_check(value, self.min_value, self.max_value)
|
||||
|
@ -177,11 +176,10 @@ class Int64Field(BaseIntField):
|
|||
class BaseFloatField(Field):
|
||||
|
||||
def to_python(self, value):
|
||||
if isinstance(value, float):
|
||||
return value
|
||||
if isinstance(value, basestring) or isinstance(value, int):
|
||||
try:
|
||||
return float(value)
|
||||
raise ValueError('Invalid value for %s - %r' % (self.__class__.__name__, value))
|
||||
except:
|
||||
raise ValueError('Invalid value for %s - %r' % (self.__class__.__name__, value))
|
||||
|
||||
|
||||
class Float32Field(BaseFloatField):
|
||||
|
|
Loading…
Reference in New Issue
Block a user