Repository navigation
Conversation
i8 is a signed 8-bit integer. The implementation mostly follows i16, and there are no major differences other than the width (int8_t in C). Existing explicit conversion tests for other native int types now also cover i8. Follow-up to #22368, which added u16. Work on mypyc/mypyc#1226.
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
jhance
approved these changes
Nov 12, 2026
hnwg
added a commit
to hnwg/mypy
that referenced
this pull request
Nov 13, 2026
The u16, u32, u64 and i8 stub classes (added in python#22368, python#22373, python#22384 and python#22447) also lack __abs__.
This was referenced Nov 14, 2026
p-sawicki
pushed a commit
that referenced
this pull request
Nov 24, 2026
The C struct name of an RTuple is built as `T<length><item codes>`, but
signed native ints used the digit codes `8`, `4`, `2` and `1`. When such
a code comes right after a tuple length, the name is ambiguous, so two
different tuple types can map to the same struct name. Example:
```python
from typing import Tuple
from mypy_extensions import i8
def f() -> Tuple[Tuple[i8], Tuple[int, int, int, int, int, int, int, int, int, int, int]]:
return ((i8(5),), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11))
def g() -> Tuple[Tuple[Tuple[i8], int, int, int, int, int, int, int, int, int, int], int]:
return (((i8(6),), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 99)
```
Both return types were named `tuple_T2T11T11IIIIIIIIIII`. The C compiler
then failed with errors like `incompatible types when assigning to type
'tuple_T11' from type 'tuple_T11T11IIIIIIIIII'`. It needs a tuple with
at least 10 items, so it's unlikely in practice. The i8 code from
#22447 made it a bit easier to hit, but i16, i32 and i64
items could already trigger it with longer tuples.
This PR changes the signed native int codes to `S8`, `S4`, `S2` and
`S1`, to match the existing `U8`/`U4`/`U2`/`U1` codes for unsigned ints.
No item code starts with a digit anymore, so the length always ends at
the first non-digit and every name decodes in only one way. Names of
tuples without signed native ints stay the same. The only hardcoded
names that change are the vec pop result structs in `librt_vecs.h`
(`tuple_T2V88` becomes `tuple_T2VS8S8`, and likewise for 32 and 16
bits). Only the typedef names change, not the struct layouts.
I updated the expected names in `test_tuplename.py` and added a unit
test and a run test with the colliding pair above.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
i8 is a signed 8-bit integer. The implementation mostly follows i16, and there are no major differences other than the width (int8_t in C). Existing explicit conversion tests for other native int types now also cover i8.
Follow-up to #22368, which added u16.
Work on mypyc/mypyc#1226.