Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
ff7d4dc8
Commit
ff7d4dc8
authored
Feb 17, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
patches/python: override py3 builtin round to keep py2 behavior
parent
9968a3fd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
product/ERP5Type/patches/python.py
product/ERP5Type/patches/python.py
+38
-0
No files found.
product/ERP5Type/patches/python.py
View file @
ff7d4dc8
...
...
@@ -174,3 +174,41 @@ def patch_linecache():
linecache
.
getlines
=
getlines
patch_linecache
()
import
decimal
as
_decimal
def
round2
(
number
,
ndigits
=
None
):
"""
See Python 2 documentation.
Rounds a number to a given precision in decimal digits (default
0 digits). The result is a floating point number. Values are rounded
to the closest multiple of 10 to the power minus ndigits; if two
multiples are equally close, rounding is done away from 0.
ndigits may be negative.
"""
if
ndigits
is
None
:
ndigits
=
0
elif
hasattr
(
ndigits
,
'__index__'
):
# any type with an __index__ method should be permitted as
# a second argument
ndigits
=
ndigits
.
__index__
()
if
ndigits
<
0
:
exponent
=
10
**
(
-
ndigits
)
quotient
,
remainder
=
divmod
(
number
,
exponent
)
if
remainder
>=
exponent
//
2
and
number
>=
0
:
quotient
+=
1
return
float
(
quotient
*
exponent
)
else
:
exponent
=
_decimal
.
Decimal
(
'10'
)
**
(
-
ndigits
)
d
=
_decimal
.
Decimal
.
from_float
(
number
).
quantize
(
exponent
,
rounding
=
_decimal
.
ROUND_HALF_UP
)
return
float
(
d
)
if
sys
.
version_info
>
(
2
,
):
__builtins__
[
'round'
]
=
round2
from
AccessControl.ZopeGuards
import
safe_builtins
safe_builtins
[
'round'
]
=
round2
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment