Skip to content

[mypyc] Add librt.strings read/write functions for i8, u16, u32 and u64 - #22458

Merged
JukkaL merged 3 commits into
masterfrom
mypyc-uint-read-write
Nov 13, 2026
Merged

JukkaL merged 3 commits into
masterfrom
mypyc-uint-read-write

Conversation

@JukkaL

@JukkaL JukkaL commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Add write_u16_le and write_u16_be, and also read_ functions and variants for u32 and u64. These are very similar to the existing signed variants.

Also add write_i8 and read_i8. Reading a signed byte previously required i8(u8(b[n])), since i8(b[n]) raises OverflowError for values above 127, so having dedicated functions is useful (unlike for u8).

Work on mypyc/mypyc#1226.

Add write_u16/u32/u64_le/be and read_u16/u32/u64_le/be for packed
unsigned binary data, following the existing signed variants. These
can be used as faster alternatives to the struct "H", "I" and "Q"
format codes in compiled code.

Also add write_i8 and read_i8. Reading a signed byte previously
required i8(u8(b[n])), since i8(b[n]) raises OverflowError for
values above 127.
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JukkaL
JukkaL merged commit 027819c into master Nov 13, 2026
26 checks passed
@JukkaL
JukkaL deleted the mypyc-uint-read-write branch November 13, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants