-
-
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 |
|---|---|---|
|
|
@@ -5282,11 +5282,13 @@ static PyObject * | |
| int_as_integer_ratio_impl(PyObject *self) | ||
| /*[clinic end generated code: output=e60803ae1cc8621a input=c1aea0aa6fb85c28]*/ | ||
| { | ||
| 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); | ||
| if PyLong_CheckExact(self) | ||
| 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.
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. Hmm; good point. There's a precedent here in the form of |
||
| else { | ||
| PyObject *temp = PyNumber_Positive(self); | ||
|
Contributor
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. We need another way to do this. The intent of this code is to construct a regular integer instance from an instance of an int subclass. The problem with PyNumber_Positive() is that the subclass can itself define pos() to return something other than an exact int. Elsewhere, we use _PyLong_Copy for this purpose.
Contributor
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. Is there a reason why |
||
| Py_DECREF(temp); | ||
|
Contributor
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. The DECREF needs to occur after building the tuple; otherwise, the Python integer object can (and likely will) disappear before it gets used. |
||
| return PyTuple_Pack(2, temp, _PyLong_One); | ||
| } | ||
|
rhettinger marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /*[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.
This should be:
self.assertEqual(type(Foo.X.as_integer_ratio()[0], int). Unittest doesn't use assertion statements.