bisect-kit: fix lint warnings from new lint rules
This also improved python3 compatibility.
BUG=b:140004822
TEST=pylint; unittest
Change-Id: I487e25a055190dd5d4059e8a0c0589170c182dea
diff --git a/bisect_kit/math_util.py b/bisect_kit/math_util.py
index 006f6ec..6e7024d 100644
--- a/bisect_kit/math_util.py
+++ b/bisect_kit/math_util.py
@@ -10,6 +10,8 @@
import math
import sys
+import six
+
def log(x):
"""Wrapper of log(x) handling zero and negative value."""
@@ -72,7 +74,7 @@
So we can maintain sum=|S| and sum_log=|\sum_i { p_i*log p_i }| for
incremental update.
- """
+ """ # pylint: disable=docstring-trailing-quotes
def __init__(self, p):
"""Initializes EntropyStats.
@@ -209,15 +211,20 @@
__rmul__ = __mul__
- def __div__(self, other):
+ def __truediv__(self, other):
if not isinstance(other, ExtendedFloat):
other = ExtendedFloat(other)
return ExtendedFloat(self.mantissa / other.mantissa,
self.exponent - other.exponent)
- def __rdiv__(self, other):
+ def __rtruediv__(self, other):
return ExtendedFloat(other).__div__(self)
+ # TODO(kcwu): remove __div__ and __rdiv__ once we migrated to python3
+ if six.PY2:
+ __div__ = __truediv__
+ __rdiv__ = __rtruediv__
+
def __repr__(self):
return 'ExtendedFloat(%f, %d)' % (self.mantissa, self.exponent)