Author: Daniel Patrick <>
Branch: py3.5
Changeset: r87241:02d30675260e
Date: 2016-09-19 16:12 +0100

Log:    Implement round ndigits=None behaviour as per CPython 3.5 docs

diff --git a/pypy/module/__builtin__/ 
--- a/pypy/module/__builtin__/
+++ b/pypy/module/__builtin__/
@@ -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)
         return space.get_and_call_function(round, w_number, w_ndigits)
diff --git a/pypy/module/__builtin__/test/ 
--- a/pypy/module/__builtin__/test/
+++ b/pypy/module/__builtin__/test/
@@ -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

Reply via email to