summaryrefslogtreecommitdiff
path: root/scalarfloat.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2017-08-21 17:50:19 +0200
committerAnthon van der Neut <anthon@mnt.org>2017-08-21 17:50:19 +0200
commita3ebcf7603851375fb882717f1697c9813b262cf (patch)
tree919811658adf8c43973e2e2737a3e9365b1475fd /scalarfloat.py
parenta0f924806ef8d20caf7a91171b7e631a7d74d47a (diff)
downloadruamel.yaml-a3ebcf7603851375fb882717f1697c9813b262cf.tar.gz
fix issue #149: operated on ScalarFloat cannot be dumped.0.15.32
Thanks for reporting I "fixed" this by making the operators return a normal (bare) float, as the preservation is mostly there for round-trips without operations. Contrary to ScalarInt you cannot as easily preserve the style, and that needs a lot more testing, and probably much smarter code (i.e. 1.23e4 *= 10 should probably give 1.23e5 and not 12.3e4). *If this change makes things work again without your explicit convert to bare float, please **Close** this issue.*
Diffstat (limited to 'scalarfloat.py')
-rw-r--r--scalarfloat.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/scalarfloat.py b/scalarfloat.py
index 7f7d26d..fca8be2 100644
--- a/scalarfloat.py
+++ b/scalarfloat.py
@@ -35,6 +35,7 @@ class ScalarFloat(float):
def __iadd__(self, a): # type: ignore
# type: (Any) -> Any
+ return float(self) + a
x = type(self)(self + a)
x._width = self._width # type: ignore
x._underscore = self._underscore[:] if self._underscore is not None else None # type: ignore # NOQA
@@ -42,6 +43,7 @@ class ScalarFloat(float):
def __ifloordiv__(self, a): # type: ignore
# type: (Any) -> Any
+ return float(self) // a
x = type(self)(self // a)
x._width = self._width # type: ignore
x._underscore = self._underscore[:] if self._underscore is not None else None # type: ignore # NOQA
@@ -49,13 +51,16 @@ class ScalarFloat(float):
def __imul__(self, a): # type: ignore
# type: (Any) -> Any
+ return float(self) * a
x = type(self)(self * a)
x._width = self._width # type: ignore
x._underscore = self._underscore[:] if self._underscore is not None else None # type: ignore # NOQA
+ x._prec = self._prec # check for others
return x
def __ipow__(self, a): # type: ignore
# type: (Any) -> Any
+ return float(self) ** a
x = type(self)(self ** a)
x._width = self._width # type: ignore
x._underscore = self._underscore[:] if self._underscore is not None else None # type: ignore # NOQA
@@ -63,6 +68,7 @@ class ScalarFloat(float):
def __isub__(self, a): # type: ignore
# type: (Any) -> Any
+ return float(self) - a
x = type(self)(self - a)
x._width = self._width # type: ignore
x._underscore = self._underscore[:] if self._underscore is not None else None # type: ignore # NOQA