Author: Daniel Patrick <danieljudepatr...@gmail.com>
Branch: py3.5
Changeset: r87241:02d30675260e
Date: 2016-09-19 16:12 +0100
http://bitbucket.org/pypy/pypy/changeset/02d30675260e/

Log:    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 w_ndigits is None or w_ndigits is space.w_None:
         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
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to