Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds boolean support.
  • Loading branch information
lisroach committed Sep 10, 2018
commit 3cd076c01428c89ac75ffc4e2ff1c5664576fb08
7 changes: 4 additions & 3 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,10 @@ class`. In addition, it provides a few more methods:

.. method:: int.as_integer_ratio()

Return a pair of integers whose ratio is exactly equal to the original integer
and with a positive denominator. The integer ratio of integers (whole numbers)
is always the integer as the numerator and 1 as the denominator.
Return a pair of integers whose ratio is exactly equal to the original
integer and with a positive denominator. The integer ratio of integers
(whole numbers) is always the integer as the numerator and 1 as the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

``1``

denominator.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A versionadded directive needs to be added. Also, the developer's guide states that reST files should use an indentation of 3 spaces.

.. versionadded:: 3.8

Expand Down
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ Other Language Changes
* Added support of ``\N{name}`` escapes in :mod:`regular expressions <re>`.
(Contributed by Jonathan Eunice and Serhiy Storchaka in :issue:`30688`.)

* The ``int`` type now has a new ``as_integer_ratio`` method compatible
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add links:

:class:`int`
:meth:`~int.as_integer_ratio`
:meth:`float.as_integer_ratio`

with the existing ``float.as_integer_ratio`` method.
(Contributed by Lisa Roach in :issue:`33073`.)


New Modules
===========
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def non_Python_modules(): r"""
True
>>> real_tests = [t for t in tests if len(t.examples) > 0]
>>> len(real_tests) # objects that actually have doctests
8
9
>>> for t in real_tests:
... print('{} {}'.format(len(t.examples), t.name))
...
Expand All @@ -675,6 +675,7 @@ def non_Python_modules(): r"""
2 builtins.float.hex
1 builtins.hex
1 builtins.int
4 builtins.int.as_integer_ratio
2 builtins.int.bit_length
1 builtins.oct

Expand Down
12 changes: 10 additions & 2 deletions Lib/test/test_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,9 +1350,17 @@ def test_shift_bool(self):
self.assertEqual(type(value >> shift), int)

def test_as_integer_ratio(self):
tests = [10, 0, -10, 1, 3]
tests = [10, 0, -10, 1]
for value in tests:
self.assertEqual(value.as_integer_ratio(), (value, 1))
numerator, denominator = value.as_integer_ratio()
self.assertEqual((numerator, denominator), (value, 1))
self.assertIsInstance(numerator, int)
self.assertIsInstance(denominator, int)

def test_as_integer_ratio_bool(self):
self.assertEqual(True.as_integer_ratio(), (1, 1))
self.assertEqual(False.as_integer_ratio(), (0, 1))



if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,7 @@ Juan M. Bello Rivas
Mohd Sanad Zaki Rizvi
Davide Rizzo
Anthony Roach
Lisa Roach
Carl Robben
Ben Roberts
Mark Roberts
Expand Down
4 changes: 1 addition & 3 deletions Objects/clinic/longobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5280,9 +5280,13 @@ and with a positive denominator.

static PyObject *
int_as_integer_ratio_impl(PyObject *self)
/*[clinic end generated code: output=e60803ae1cc8621a input=ce9c7768a1287fb9]*/
/*[clinic end generated code: output=e60803ae1cc8621a input=c1aea0aa6fb85c28]*/
{
return PyTuple_Pack(2, self, _PyLong_One);
if (self == Py_True)
return PyTuple_Pack(2, _PyLong_One, _PyLong_One);
if (self == Py_False)
return PyTuple_Pack(2, _PyLong_Zero, _PyLong_One);
return PyTuple_Pack(2, self, _PyLong_One);
}

/*[clinic input]
Expand Down