Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r87243:5f9c690d2444
Date: 2016-09-20 12:22 +0200
http://bitbucket.org/pypy/pypy/changeset/5f9c690d2444/
Log: Merged in remarkablerocket/pypy/py3.5 (pull request #480)
Implement round ndigits=None behaviour as per CPython 3.5 docs
diff --git a/pypy/module/__builtin__/operation.py
b/pypy/module/__builtin__/operation.py
--- a/pypy/module/__builtin__/operation.py
+++ b/pypy/module/__builtin__/operation.py
@@ -100,13 +100,13 @@
"""round(number[, ndigits]) -> number
Round a number to a given precision in decimal digits (default 0 digits).
-This returns an int when called with one argument, otherwise the
-same type as the number. ndigits may be negative."""
+This returns an int when called with one argument or if ndigits=None,
+otherwise the same type as the number. ndigits may be negative."""
round = space.lookup(w_number, '__round__')
if round is None:
raise oefmt(space.w_TypeError,
"type %T doesn't define __round__ method", w_number)
- if w_ndigits is None:
+ if space.is_none(w_ndigits):
return space.get_and_call_function(round, w_number)
else:
return space.get_and_call_function(round, w_number, w_ndigits)
diff --git a/pypy/module/__builtin__/test/test_builtin.py
b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -814,8 +814,9 @@
raises(TypeError, round, t)
raises(TypeError, round, t, 0)
- raises(TypeError, round, 3, None)
- raises(TypeError, round, 3.0, None)
+ assert round(3, ndigits=None) == 3
+ assert round(3.0, ndigits=None) == 3
+ assert type(round(3.0, ndigits=None)) is int
def test_vars_obscure_case(self):
class C_get_vars(object):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit