◐ Shell
clean mode source ↗

gh-111140: Improve PyLong_AsNativeBytes API doc example & improve the test by gpshead · Pull Request #115380 · python/cpython

added 2 commits

February 12, 2024 14:46
This also makes the example more realistic, people are unlikely to want
this API to get a value into a simple `int` type, we've got direct APIs
for that. So have the example use an array as if it is a bignum of its
own.

I start by fixing the API name in the doc example as scoder@ noted in
the original code review after merge.  But I noticed one thing in the
test that could be done better so I added that as well: we need to
guarantee that all bytes of the result are overwritten.  This now
pre-fills the result with data in order to ensure that.  _(assuming
ctypes isn't undoing that behind the scenes...)_

@gpshead gpshead marked this pull request as ready for review

February 12, 2024 23:16

@gpshead gpshead changed the title gh-11140: Correct AsNativeBytes API docs & improve the test gh-11140: Improve PyLong_AsNativeBytes API doc example & improve the test

Feb 12, 2024

@zooba zooba changed the title gh-11140: Improve PyLong_AsNativeBytes API doc example & improve the test gh-111140: Improve PyLong_AsNativeBytes API doc example & improve the test

Feb 13, 2024

@gpshead

zooba

We don't want examples to encourage PyErr_Occurred on modern APIs.
Co-authored-by: Steve Dower <steve.dower@microsoft.com>

@gpshead gpshead marked this pull request as ready for review

February 21, 2024 01:04

zooba

@gpshead

woodruffw pushed a commit to woodruffw-forks/cpython that referenced this pull request

Mar 4, 2024
…ve the test (python#115380)

This expands the examples to cover both realistic use cases for the API.
    
I noticed thing in the test that could be done better so I added those as well: We need to guarantee that all bytes of the result are overwritten and that too many are not written.  Tests now pre-fills the result with data in order to ensure that.

Co-authored-by: Steve Dower <steve.dower@microsoft.com>

diegorusso pushed a commit to diegorusso/cpython that referenced this pull request

Apr 17, 2024
…ve the test (python#115380)

This expands the examples to cover both realistic use cases for the API.
    
I noticed thing in the test that could be done better so I added those as well: We need to guarantee that all bytes of the result are overwritten and that too many are not written.  Tests now pre-fills the result with data in order to ensure that.

Co-authored-by: Steve Dower <steve.dower@microsoft.com>

LukasWoodtli pushed a commit to LukasWoodtli/cpython that referenced this pull request

Jan 22, 2025
…ve the test (python#115380)

This expands the examples to cover both realistic use cases for the API.
    
I noticed thing in the test that could be done better so I added those as well: We need to guarantee that all bytes of the result are overwritten and that too many are not written.  Tests now pre-fills the result with data in order to ensure that.

Co-authored-by: Steve Dower <steve.dower@microsoft.com>