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
Revert int.as_integer_ration() docstring/rst docs to the original patch
  • Loading branch information
skirpichev committed Feb 27, 2023
commit fdb47d277f3b374e23adc7f8d22f5427f5f1ae63
5 changes: 4 additions & 1 deletion Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,10 @@ class`. In addition, it provides a few more methods:

.. method:: int.as_integer_ratio()

Given an integer ``x``, return the tuple ``(int(x), 1)``.
Return a pair of integers whose ratio is equal to the original
integer and has a positive denominator. The integer ratio of integers
(whole numbers) is always the integer as the numerator and ``1`` as the
denominator.
Comment thread
skirpichev marked this conversation as resolved.

.. versionadded:: 3.8

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 @@ -711,7 +711,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
13
14
>>> for t in real_tests:
... print('{} {}'.format(len(t.examples), t.name))
...
Expand All @@ -723,6 +723,7 @@ def non_Python_modules(): r"""
2 builtins.float.hex
1 builtins.hex
1 builtins.int
3 builtins.int.as_integer_ratio
2 builtins.int.bit_count
2 builtins.int.bit_length
5 builtins.memoryview.hex
Expand Down
13 changes: 11 additions & 2 deletions Objects/clinic/longobject.c.h

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

13 changes: 11 additions & 2 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -6020,12 +6020,21 @@ int_bit_count_impl(PyObject *self)
/*[clinic input]
int.as_integer_ratio

Given an integer x, return the tuple (int(x), 1).
Return a pair of integers, whose ratio is equal to the original int.

The ratio is in lowest terms and has a positive denominator.

>>> (10).as_integer_ratio()
Comment thread
skirpichev marked this conversation as resolved.
(10, 1)
>>> (-10).as_integer_ratio()
(-10, 1)
>>> (0).as_integer_ratio()
(0, 1)
[clinic start generated code]*/

static PyObject *
int_as_integer_ratio_impl(PyObject *self)
/*[clinic end generated code: output=e60803ae1cc8621a input=258f5b08307e7dcd]*/
/*[clinic end generated code: output=e60803ae1cc8621a input=384ff1766634bec2]*/
{
PyObject *ratio_tuple;
PyObject *numerator = long_long(self);
Expand Down