Add mypyc native int types i64, i32, i16 and u8 (#31)

In code compiled with mypyc, these can be used in annotations to use
faster native int operations that don't check for overflow, as an
alternative to the default arbitrary-precision int type.

See mypyc/mypyc/issues/837 for more context. Note that only i64 and
i32 are currently supported by mypyc, but I'm adding the planned i16
and u8 types as well since their implementation is essentially the
same.

These are not real classes. In particular, there can be no instances
of these types. In code that is not compiled with mypyc, there are
just regular 'int' objects, in order to allow code using these types
to be run without compilation. In code compiled with mypyc, these are
represented as native integers that don't have a 1:1 Python
replacement. The native integers are impliciticly converted to/from
'int' objects when boxed/unboxed.

I originally was planning to make these aliases of `int`, but there
are runtime type checking and introspection use cases where it's
important to make these distinct objects.

The types only support a few runtime operations:

* Conversions from numbers and strings
* `isinstance` checks

We could also add at least the `from_bytes` class method, but it
doesn't seem urgent as long as mypyc doesn't support it as a primitive
operation.
3 files changed
tree: 300040061f7cf1bb499a248edd59529e8213f243
  1. tests/
  2. .gitignore
  3. .travis.yml
  4. LICENSE
  5. MANIFEST.in
  6. mypy_extensions.py
  7. README.md
  8. setup.cfg
  9. setup.py
  10. tox.ini
README.md

Mypy Extensions

The mypy_extensions module defines extensions to the Python standard library typing module that are supported by the mypy type checker and the mypyc compiler.