How well would something like this solve your issue?

import typing
if typing.TYPE_CHECKING:
    class i8(int): pass
else:
    from ctypes import c_int8 as i8

Or perhaps instead of the class definition use a type alias:

    i8 = int

On Wed, May 19, 2021 at 1:59 PM Arun Sharma <arun@sharma-home.net> wrote:

I'm aware that the python3 type system primarily supports arbitrary precision integers and there is no support for type checking fixed width integers.

However, when python is used as an approachable first language for data scientists, scientists interested in numerical analysis and possibly other generic use cases, one common technique is to map python's type system to that of a lower level underlying system.

I'm primarily coming at it from the third  use case in the form of py2many, a transpiler for converting python to many statically typed C-like languages. I suspect pytorch, tensorflow or anything that maps python to vectorized hardware efficiently has to deal with the precision of integers.

Canonical use case:

```
#!/usr/bin/env python3

from ctypes import c_int8 as i8

def test():
    a: i8 = 10
    b: i8 = 20
    c = a + b
    reveal_type(c)
```

Also would love to have type checkers infer ranges and throw errors for cases like:

c: i8 = 300

Doing so would significantly benefit the use case of generating secure C++/Rust code from python source:

https://github.com/adsharma/py2many/issues/233

Eric Traut suggested I post to the mailing list. More context here:

https://github.com/microsoft/pyright/issues/1872

 -Arun

_______________________________________________
Typing-sig mailing list -- typing-sig@python.org
To unsubscribe send an email to typing-sig-leave@python.org
https://mail.python.org/mailman3/lists/typing-sig.python.org/
Member address: guido@python.org


--
--Guido van Rossum (python.org/~guido)
Pronouns: he/him (why is my pronoun here?)