micropython/docs/library
Angus Gratton c97d3534dc py/objint: Fix int.to_bytes() buffer size checks.
* No longer overflows if byte size is 0 (closes #13041)
* Raises OverflowError in any case where number won't fit into byte length
  (Now matches CPython, previously MicroPython would return a truncated
  bytes object.)
* Document that micropython int.to_bytes() doesn't implement the optional
  signed kwarg, but will behave as if signed=True when the integer is
  negative (this is the current behaviour). Add tests for this also.

Requires changes for small ints, MPZ large ints, and "long long" large
ints.

Adds a new set of unit tests for ints between 32 and 64 bits to increase
coverage of "long long" large ints, which are otherwise untested.

Tested on unix port (64 bit small ints, MPZ long ints) and Zephyr STM32WB
board (32 bit small ints, long long large ints).

Untested on a port whose native format is big endian (don't have one at
hand).

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-04-10 13:52:29 +10:00
..
_thread.rst
array.rst
asyncio.rst
binascii.rst
bluetooth.rst
btree.rst
builtins.rst py/objint: Fix int.to_bytes() buffer size checks. 2024-04-10 13:52:29 +10:00
cmath.rst
collections.rst
cryptolib.rst
deflate.rst
errno.rst
esp.rst
esp32.rst
espnow.rst
framebuf.rst
gc.rst
gzip.rst
hashlib.rst
heapq.rst
index.rst
io.rst
json.rst
lcd160cr.rst
machine.ADC.rst
machine.ADCBlock.rst
machine.ADCWiPy.rst
machine.I2C.rst
machine.I2S.rst
machine.PWM.rst
machine.Pin.rst
machine.RTC.rst
machine.SD.rst
machine.SDCard.rst
machine.SPI.rst
machine.Signal.rst
machine.Timer.rst
machine.TimerWiPy.rst
machine.UART.rst
machine.USBDevice.rst
machine.WDT.rst
machine.rst
math.rst
micropython.rst
neopixel.rst
network.LAN.rst
network.WIZNET5K.rst
network.WLAN.rst
network.WLANWiPy.rst
network.rst
openamp.rst
os.rst
platform.rst
pyb.ADC.rst
pyb.Accel.rst
pyb.CAN.rst
pyb.DAC.rst
pyb.ExtInt.rst
pyb.Flash.rst
pyb.I2C.rst
pyb.LCD.rst
pyb.LED.rst
pyb.Pin.rst
pyb.RTC.rst
pyb.SPI.rst
pyb.Servo.rst
pyb.Switch.rst
pyb.Timer.rst
pyb.UART.rst
pyb.USB_HID.rst
pyb.USB_VCP.rst
pyb.rst
random.rst
re.rst
rp2.DMA.rst
rp2.Flash.rst
rp2.PIO.rst
rp2.StateMachine.rst
rp2.rst
select.rst
socket.rst
ssl.rst
stm.rst
struct.rst
sys.rst
time.rst
uctypes.rst
vfs.rst
wipy.rst
wm8960.rst
zephyr.DiskAccess.rst
zephyr.FlashArea.rst
zephyr.rst
zephyr.zsensor.rst
zlib.rst