[pypy-commit] pypy py3.5: add some docstrings expected by test_doctest, adapt its counts

pjenvey pypy.commits at gmail.com
Sun Jan 15 14:54:33 EST 2017


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3.5
Changeset: r89596:1855c0def876
Date: 2017-01-15 11:53 -0800
http://bitbucket.org/pypy/pypy/changeset/1855c0def876/

Log:	add some docstrings expected by test_doctest, adapt its counts

diff --git a/lib-python/3/test/test_doctest.py b/lib-python/3/test/test_doctest.py
--- a/lib-python/3/test/test_doctest.py
+++ b/lib-python/3/test/test_doctest.py
@@ -8,6 +8,7 @@
 import os
 import sys
 
+is_pypy = support.check_impl_detail(pypy=True)
 
 # NOTE: There are some additional tests relating to interaction with
 #       zipimport in the test_zipimport_support test module.
@@ -659,7 +660,8 @@
 
     >>> import builtins
     >>> tests = doctest.DocTestFinder().find(builtins)
-    >>> 790 < len(tests) < 810 # approximate number of objects with docstrings
+    >>> lo, hi = (120, 140) if is_pypy else (790, 810)
+    >>> lo < len(tests) < hi # approximate number of objects with docstrings
     True
     >>> real_tests = [t for t in tests if len(t.examples) > 0]
     >>> len(real_tests) # objects that actually have doctests
diff --git a/pypy/module/__builtin__/app_operation.py b/pypy/module/__builtin__/app_operation.py
--- a/pypy/module/__builtin__/app_operation.py
+++ b/pypy/module/__builtin__/app_operation.py
@@ -1,16 +1,31 @@
 import _operator
 
 def bin(x):
-    """Return the binary representation of an integer."""
+    """Return the binary representation of an integer.
+
+    >>> bin(2796202)
+    '0b1010101010101010101010'
+
+    """
     value = _operator.index(x)
     return value.__format__("#b")
 
 def oct(x):
-    """Return the octal representation of an integer."""
+    """Return the octal representation of an integer.
+
+    >>> oct(342391)
+    '0o1234567'
+
+    """
     x = _operator.index(x)
     return x.__format__("#o")
 
 def hex(x):
-    """Return the hexadecimal representation of an integer."""
+    """Return the hexadecimal representation of an integer.
+
+    >>> hex(12648430)
+    '0xc0ffee'
+
+    """
     x = _operator.index(x)
     return x.__format__("#x")
diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -246,6 +246,15 @@
     @staticmethod
     @unwrap_spec(s=str)
     def descr_fromhex(space, w_cls, s):
+        """float.fromhex(string) -> float
+
+        Create a floating-point number from a hexadecimal string.
+        >>> float.fromhex('0x1.ffffp10')
+        2047.984375
+        >>> float.fromhex('-0x1p-1074')
+        -5e-324
+
+        """
         length = len(s)
         i = 0
         value = 0.0
@@ -592,6 +601,20 @@
         return space.wrap(math.floor(v) == v)
 
     def descr_as_integer_ratio(self, space):
+        """float.as_integer_ratio() -> (int, int)
+
+        Return a pair of integers, whose ratio is exactly equal to the
+        original float and with a positive denominator.  Raise
+        OverflowError on infinities and a ValueError on NaNs.
+
+        >>> (10.0).as_integer_ratio()
+        (10, 1)
+        >>> (0.0).as_integer_ratio()
+        (0, 1)
+        >>> (-.25).as_integer_ratio()
+        (-1, 4)
+
+        """
         value = self.floatval
         try:
             num, den = float_as_rbigint_ratio(value)
@@ -608,6 +631,17 @@
         return space.newtuple([space.int(w_num), space.int(w_den)])
 
     def descr_hex(self, space):
+        """float.hex() -> string
+
+        Return a hexadecimal representation of a floating-point
+        number.
+
+        >>> (-0.1).hex()
+        '-0x1.999999999999ap-4'
+        >>> 3.14159.hex()
+        '0x1.921f9f01b866ep+1'
+
+        """
         TOHEX_NBITS = rfloat.DBL_MANT_DIG + 3 - (rfloat.DBL_MANT_DIG + 2) % 4
         value = self.floatval
         if not isfinite(value):


More information about the pypy-commit mailing list