-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
3 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Mypy Extensions | ||
=============== | ||
|
||
The "mypy_extensions" module defines experimental extensions to the | ||
standard "typing" module that are supported by the mypy typechecker. | ||
|
||
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. |
This file contains 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
This file contains 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