summaryrefslogtreecommitdiff
path: root/odoo/tools/float_utils.py
diff options
context:
space:
mode:
authorAdrian Torres <adt@odoo.com>2018-11-08 15:03:33 +0000
committerAdrian Torres <adt@odoo.com>2018-11-29 09:28:17 +0000
commit758382b3a73da024d6e1dc04a474d2868223767a (patch)
treee37ea57fb6efabf9a14d30b39a74af664ddd1ed3 /odoo/tools/float_utils.py
parent52f5528cfb6d1152ee226e268247dc685a8ba329 (diff)
[REM] pycompat: remove python 2 shims and helpers
Odoo no longer supports python 2, thus some of these helpers can and have been replaced by python 3 built-ins, therefore there is no need for them to stay defined. The removed helpers are: * izip, imap and ifilter * unichr, text_type * implements_to_string, implements_iterator * string_types, integer_types * to_native The python 2 shims have also been removed, and only the python 3 helpers have been kept, because they can still be usable (i.e. accepting both bytes and str for functions that can only accept one of the two) [REM] pyjsparser: remove PY3 shims They're no longer necessary as Odoo doesn't officially support python 2 anymore. closes odoo/odoo#28519
Diffstat (limited to 'odoo/tools/float_utils.py')
-rw-r--r--odoo/tools/float_utils.py35
1 files changed, 16 insertions, 19 deletions
diff --git a/odoo/tools/float_utils.py b/odoo/tools/float_utils.py
index c5c2946a5ce..12881503f32 100644
--- a/odoo/tools/float_utils.py
+++ b/odoo/tools/float_utils.py
@@ -2,28 +2,25 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from __future__ import print_function
+import builtins
import math
-if not pycompat.PY2:
- import builtins
- def round(f):
- # P3's builtin round differs from P2 in the following manner:
- # * it rounds half to even rather than up (away from 0)
- # * round(-0.) loses the sign (it returns -0 rather than 0)
- # * round(x) returns an int rather than a float
- #
- # this compatibility shim implements Python 2's round in terms of
- # Python 3's so that important rounding error under P3 can be
- # trivially fixed, assuming the P2 behaviour to be debugged and
- # correct.
- roundf = builtins.round(f)
- if builtins.round(f + 1) - roundf != 1:
- return f + math.copysign(0.5, f)
- # copysign ensures round(-0.) -> -0 *and* result is a float
- return math.copysign(roundf, f)
-else:
- round = round
+def round(f):
+ # P3's builtin round differs from P2 in the following manner:
+ # * it rounds half to even rather than up (away from 0)
+ # * round(-0.) loses the sign (it returns -0 rather than 0)
+ # * round(x) returns an int rather than a float
+ #
+ # this compatibility shim implements Python 2's round in terms of
+ # Python 3's so that important rounding error under P3 can be
+ # trivially fixed, assuming the P2 behaviour to be debugged and
+ # correct.
+ roundf = builtins.round(f)
+ if builtins.round(f + 1) - roundf != 1:
+ return f + math.copysign(0.5, f)
+ # copysign ensures round(-0.) -> -0 *and* result is a float
+ return math.copysign(roundf, f)
def _float_check_precision(precision_digits=None, precision_rounding=None):
assert (precision_digits is not None or precision_rounding is not None) and \