From 758382b3a73da024d6e1dc04a474d2868223767a Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Thu, 8 Nov 2018 15:03:33 +0000 Subject: [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 --- odoo/tools/float_utils.py | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'odoo/tools/float_utils.py') 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 \ -- cgit v1.2.3