8000 Comparing master...native-int-types · python/mypy_extensions · GitHub
[go: up one dir, main page]

Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: python/mypy_extensions
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: python/mypy_extensions
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: native-int-types
Choose a head ref
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Jan 29, 2023

  1. Add mypyc native int types i64, i32, i16 and u8

    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.
    JukkaL committed Jan 29, 2023
    Configuration menu
    Copy the full SHA
    841aa1c View commit details
    Browse the repository at this point in the history
Loading
0