-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-126061: Add PyLong_IsPositive/Zero/Negative() functions #126065
base: main
Are you sure you want to change the base?
Conversation
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 have tests and an entry in Doc/whatsnew/3.14.rst
I'll get to reviewing this sometime today. |
@rruuaanng, please avoid force-pushes. |
Sorry, there are a lot of changes that need to be rolled back. I will pay attention. :( |
On Mon, Oct 28, 2024 at 02:55:40AM -0700, RUANG (James Roy) wrote:
Sorry, there are a lot of changes that need to be rolled back. I will pay
attention. :(
In the end - individual commits will be squashed anyway.
|
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.
Nitpick: Use op
for names, not obj
Given the number of comments,I'll reply here. I apologize for any inconvenience. The error handling implementation mentioned above was based on discussions in Capigroup, as Edit |
Yes, I'm not asking to change how errors are handled. I'm worried about the error message. |
Looking on other functions, rather |
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
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.
LGTM in general. Please add tests. Look at Modules/_testcapi/long.c
and Lib/test/test_capi/test_long.py
.
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.
I do see Serhiy's point of using the type name rather than the repr, but it's nice when "invalid type" errors are more unified, so I would prefer if it matched what was raised when using PyArg*
. AFAICS, the only other function using the current message is PyLong_GetSign
.
No. PyLong_AsNativeBytes, PyLong_AsUnsignedLongLong, PyLong_AsDouble, PyLong_AsSsize_t, etc. |
Ah, I see it in |
On Tue, Oct 29, 2024 at 04:40:08AM -0700, Peter Bierma wrote:
Ah, I see it in PyLong_AsNativeBytes, but that looks like the only other
location. Could you point me to where it's thrown in the other functions?
(GitHub search might be acting up.)
Correct phrase to grep is "an integer is required" ;)
|
Ok, so that's not |
I've made changes :) |
See |
It exists only to keep in sync with |
Ah, it's probably a way to signal that |
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.
Per the comments from Sergey and Erlend, it should be expected
, not expect
.
I see, but I wonder if there is any reason to change GetSign as well. |
There could be, but that's for another PR. I'm also happy with the phrase |
Maybe it's too long? Maybe keeping |
That's say, we should change it to Edit
|
I'm happy to approve this if you change it to an |
@@ -571,6 +571,42 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate. | |||
.. versionadded:: 3.14 | |||
.. c:function:: int PyLong_IsPositive(PyObject *obj) | |||
Check if the integer object *obj* is positive. |
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.
it's very positive
Also it's very negative:D
Lets just stick with math terminolgy.
Sorry peter. I'm not sure we need to be consistent with the test for |
No, |
Emmm..., Look at this, actually my point is the same. I think we just need to identify a problem, and it will trigger this when the type is wrong. |
@@ -571,6 +571,39 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate. | |||
.. versionadded:: 3.14 | |||
.. c:function:: int PyLong_IsPositive(PyObject *obj) | |||
Check if the integer object *obj* is positive. |
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.
If you dislike strictly, I suggest:
Check if the integer object *obj* is positive. | |
Check if the integer object *obj* is positive: greater than zero. |
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.
I don't feel this addition is needed.
But at least this form is less confusing than "strictly positive". Maybe: "Check if the integer object obj is positive, i.e. greater than zero."
Misc/NEWS.d/next/C_API/2024-10-28-15-56-03.gh-issue-126061.Py51_1.rst
Outdated
Show resolved
Hide resolved
@serhiy-storchaka, I think this is ready for final review. |
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.
OK, I've ran out of things to nitpick 😄
I'm not particularly happy about the tests, but in hindsight it's probably fine. Though, if we break it in the future don't say I didn't warn you!
Thank you @rruuaanng for the responsiveness, and thank you @skirpichev for all the technical insight (and for dealing with my pickiness)!
📚 Documentation preview 📚: https://cpython-previews--126065.org.readthedocs.build/