Support better param conversions to/from numeric subclasses.
--HG-- extra : convert_revision : 2ccb75b0912a384789458710fd9bbb65626f839e
This commit is contained in:
parent
4c0014a187
commit
e6d7e8af21
1 changed files with 10 additions and 1 deletions
|
@ -237,6 +237,12 @@ class NumericParamValue(ParamValue):
|
||||||
def __float__(self):
|
def __float__(self):
|
||||||
return float(self.value)
|
return float(self.value)
|
||||||
|
|
||||||
|
def __long__(self):
|
||||||
|
return long(self.value)
|
||||||
|
|
||||||
|
def __int__(self):
|
||||||
|
return int(self.value)
|
||||||
|
|
||||||
# hook for bounds checking
|
# hook for bounds checking
|
||||||
def _check(self):
|
def _check(self):
|
||||||
return
|
return
|
||||||
|
@ -308,8 +314,11 @@ class CheckedInt(NumericParamValue):
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
self.value = convert.toInteger(value)
|
self.value = convert.toInteger(value)
|
||||||
elif isinstance(value, (int, long, float)):
|
elif isinstance(value, (int, long, float, NumericParamValue)):
|
||||||
self.value = long(value)
|
self.value = long(value)
|
||||||
|
else:
|
||||||
|
raise TypeError, "Can't convert object of type %s to CheckedInt" \
|
||||||
|
% type(value).__name__
|
||||||
self._check()
|
self._check()
|
||||||
|
|
||||||
class Int(CheckedInt): cxx_type = 'int'; size = 32; unsigned = False
|
class Int(CheckedInt): cxx_type = 'int'; size = 32; unsigned = False
|
||||||
|
|
Loading…
Reference in a new issue