GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-108444: Add PyLong_AsInt() public function by vstinner · Pull Request #108445 · python/cpython Conversation
| ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@serhiy-storchaka: You added the function 10 years, what do you think of making it public now? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
* Rename _PyLong_AsInt() to PyLong_AsInt(). * Add documentation. * Add test. * For now, keep _PyLong_AsInt() as an alias to PyLong_AsInt().
Just last week I thought about this. Should we add also Should we add |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Having to check Maybe the API should:
I would prefer to not add too many functions. The |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| with self.assertRaises(OverflowError): | ||
| PyLong_AsInt(INT_MAX + 1) | ||
|
|
||
| # invalid type |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please add also tests for objects with __index__
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Ok, I added a test
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,4 @@ | |||
| Add :c:func:`PyLong_AsInt` function: similar to :c:func:`PyLong_AsLong`, but | |||
| store the result in a C :c:expr:`int` instead of a C :c:expr:`long`. | |||
| Previously, it was known as the the private function :c:func:`!_PyLong_AsInt` | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| Previously, it was known as the the private function :c:func:`!_PyLong_AsInt` | |
| Previously, it was known as the private function :c:func:`!_PyLong_AsInt` |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…OSS.rst Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Kirill Podoprigora <[email protected]>
|
This API extends the list of problematic APIs listed in capi-workgroup/problems#1. How about a non-ambiguous return value? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
See also: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I suppose that the similar proportion should be in the third-party code. But they use |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
That number is true, but the majority of it comes from Argument Clinic. If you subtract generated code, you will see that the actual number is less then a tenth of 420: $ git grep _PyLong_AsInt | grep -v clinic | wc -l 36 I'm not sure a handful of cases warrants the introduction of yet another ambiguous API. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
And what? Argument Clinic uses |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The point is that there is not 420 occurrences of You wrote:
I assumed you meant that it was not easy to use a different API because of the huge number of occurrences (420). My interpretation was that since the actual number of occurrences that need replacement is significantly lower, your argument of it being hard to replace is moot. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
No, I mean that you can expect a huge number of use cases for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Aha, sorry, I misunderstood you. Yes, that is a valid point. I withdraw my complain. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I'm well aware of PyLong_AsLong() API issue. But if we fix the API, I would prefer to fix the whole PyLong API family, not a single function. It would be surprising to have a single function with a similar name, but a different API. By the way, the private Affected projects (9):
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
There's a new commit after the PR has been approved. @serhiy-storchaka: please review the changes made to this pull request. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yes, that makes sense. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The function is more if it's worth it to propose a new set of PyLong_AsLong-like function which avoid having to check PyErr_Occurred(): API like |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
... or even better: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I don't think this should be added to the stable ABI now. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The private _PyLong_AsInt() function seems to be pretty commonly used in the wild, so adding it as public API helps people to migrate to this new public C API. I would like to add it the limited C API to be able to use it in C code generated by Argument Clinic which seems to like a lot PyLong_AsInt(). For example, in the main branch, there are 70 For now, there is no concrete plan to deprecate PyLong_AsLong() nor replacement. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Is there a way to gather some reliable statistics about non-public functions used in third-party code? If they are used in a number of non-toy projects, we should consider to provide a public API to satisfy the need. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I'm on board with that. But we should also use these opportunities to provide better API. Private functions can get away with being hacky. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Known issues of PyLong_AsLong() were discussed in previous comments and it was decided to add PyLong_AsInt() as it is anyway. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.