-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
bpo-33073: Adding as_integer_ratio to ints. #8750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ff0790e
d1daadc
3b89b6f
48c7dd0
4ca566a
2336cb4
673a0ca
5102589
a935a7b
3cd076c
028417a
2028d97
89a0d9d
148225c
ac0f11f
cb9c978
d311b83
d3ef843
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1352,7 +1352,7 @@ def test_shift_bool(self): | |
| def test_as_integer_ratio(self): | ||
| tests = [10, 0, -10, 1, 3] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why so much similar cases are needed? Add tests for booleans and other int subclasses. Check types of numerator and denominator. |
||
| for value in tests: | ||
| self.assertEqual((value).as_integer_ratio(), (value, 1)) | ||
| self.assertEqual(value.as_integer_ratio(), (value, 1)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5268,8 +5268,6 @@ Return integer ratio. | |
| Return a pair of integers, whose ratio is exactly equal to the original int | ||
| and with a positive denominator. | ||
|
|
||
| Raise OverflowError on infinities and a ValueError on NaNs. | ||
|
|
||
| >>> (10).as_integer_ratio() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need so much examples in a docstring?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's useful to have at least one positive and one negative example, so that it's obvious at a glance that the behaviour for negatives is to give (for example) |
||
| (10, 1) | ||
| >>> (0).as_integer_ratio() | ||
|
|
@@ -5284,14 +5282,7 @@ static PyObject * | |
| int_as_integer_ratio_impl(PyObject *self) | ||
| /*[clinic end generated code: output=e60803ae1cc8621a input=ce9c7768a1287fb9]*/ | ||
| { | ||
| PyObject *denominator = NULL; | ||
| PyObject *result_pair = NULL; | ||
|
|
||
| denominator = PyLong_FromLong(1); | ||
| result_pair = PyTuple_Pack(2, self, denominator); | ||
|
|
||
| Py_DECREF(denominator); | ||
| return result_pair; | ||
| return PyTuple_Pack(2, self, _PyLong_One) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a missing semicolon at the end of this line; I think that's why the continuous integration builds are failing. Also, please change the indentation of this line to 4 spaces instead of 2 spaces, following PEP7. Thanks! |
||
| } | ||
|
|
||
| /*[clinic input] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A
versionaddeddirective needs to be added. Also, the developer's guide states that reST files should use an indentation of 3 spaces.