From a3ebcf7603851375fb882717f1697c9813b262cf Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Mon, 21 Aug 2017 17:50:19 +0200 Subject: fix issue #149: operated on ScalarFloat cannot be dumped. 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.* --- scalarfloat.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'scalarfloat.py') 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 -- cgit v1.2.1