From e1569542f4b2efd3f8b34bfb16bfcb6a4452587a Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Sat, 19 Sep 2026 12:08:49 +0100 Subject: [PATCH] Add i8, u64, u32 and u16 native integer types These are similar to the existing types `u8`, `i64`, etc. Work on https://github.com/mypyc/mypyc/issues/1226. --- mypy_extensions.py | 30 +++++++++++++++++++++++++++++- tests/testextensions.py | 4 ++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/mypy_extensions.py b/mypy_extensions.py index 1910000..5497b15 100644 --- a/mypy_extensions.py +++ b/mypy_extensions.py @@ -209,6 +209,34 @@ def __new__(cls, x=0, base=_sentinel): return int(x) +class i8(metaclass=_NativeIntMeta): + def __new__(cls, x=0, base=_sentinel): + if base is not _sentinel: + return int(x, base) + return int(x) + + +class u64(metaclass=_NativeIntMeta): + def __new__(cls, x=0, base=_sentinel): + if base is not _sentinel: + return int(x, base) + return int(x) + + +class u32(metaclass=_NativeIntMeta): + def __new__(cls, x=0, base=_sentinel): + if base is not _sentinel: + return int(x, base) + return int(x) + + +class u16(metaclass=_NativeIntMeta): + def __new__(cls, x=0, base=_sentinel): + if base is not _sentinel: + return int(x, base) + return int(x) + + class u8(metaclass=_NativeIntMeta): def __new__(cls, x=0, base=_sentinel): if base is not _sentinel: @@ -216,7 +244,7 @@ def __new__(cls, x=0, base=_sentinel): return int(x) -for _int_type in i64, i32, i16, u8: +for _int_type in i64, i32, i16, i8, u64, u32, u16, u8: _int_type.__doc__ = \ """A native fixed-width integer type when used with mypyc. diff --git a/tests/testextensions.py b/tests/testextensions.py index 72a4a49..068d160 100644 --- a/tests/testextensions.py +++ b/tests/testextensions.py @@ -5,7 +5,7 @@ import warnings from contextlib import contextmanager from unittest import TestCase, main -from mypy_extensions import TypedDict, i64, i32, i16, u8 +from mypy_extensions import TypedDict, i64, i32, i16, i8, u64, u32, u16, u8 class BaseTestCase(TestCase): @@ -150,7 +150,7 @@ def test_total(self): self.assertEqual(Options.__total__, False) # noqa -native_int_types = [i64, i32, i16, u8] +native_int_types = [i64, i32, i16, i8, u64, u32, u16, u8] class MypycNativeIntTests(TestCase):