Skip to content

[mypyc] Support the u16 native integer type - #22368

Merged
JukkaL merged 1 commit into
masterfrom
mypyc-u16
Nov 4, 2026
Merged

JukkaL merged 1 commit into
masterfrom
mypyc-u16

Conversation

@JukkaL

@JukkaL JukkaL commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

u16 is an unsigned 16-bit integer, similar to the existing u8 type but wider. Operations wrap around on overflow. Values are represented as uint16_t in C, with 239 as the overlapping error value.

The internal uint16 rprimitive already existed; this promotes it to a user-visible type (mypy_extensions.u16) with unboxing/boxing (CPyLong_AsUInt16), overflow errors, conversions to/from other native ints, and docs/tests similar to u8.

The changes are mostly boilerplate.

Work on mypyc/mypyc#1226.

u16 is an unsigned 16-bit integer, similar to the existing u8 type
but wider. Operations wrap around on overflow. Values are
represented as uint16_t in C, with 239 as the overlapping error value.

The internal uint16 rprimitive already existed; this promotes it to a
user-visible type (mypy_extensions.u16) with unboxing/boxing
(CPyLong_AsUInt16), overflow errors, conversions to/from other native
ints, and docs/tests similar to u8.
@github-actions

github-actions Bot commented Nov 4, 2026

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 6db02fc into master Nov 4, 2026
26 checks passed
@JukkaL
JukkaL deleted the mypyc-u16 branch November 4, 2026 16:58
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