Skip to content

Pystachy v0.6.0

Choose a tag to compare

@github-actions github-actions released this 20 Nov 05:40
817c9cd

Pystachy v0.6.0 compiles more of the Python found in typed code such as mypy's: classes as values, objects beside numbers and strings in unions, more inferred field types, bytearray and more of the standard library. It also runs unittest suites natively and repairs results that v0.5.0 got wrong. Pystachy remains an experimental compiler for a typed subset of Python.

Classes, unions and generics

  • type[C] holds the class object of C or a subclass in variables, fields and containers. Class objects answer isinstance() and issubclass(), construct objects and call class and static methods; type[object] also holds builtin classes such as int. (alpha.2)
  • A union may hold int, float, bool or str beside objects of the program's classes, and runtime-length tuples hold objects. isinstance(), callable(), None and truth tests of x.a narrow the reads that follow.
  • A class may have several method-only secondary bases, such as mypyc traits, take type variables from its bases and derive from Iterator[...]. TypeVar takes bounds and constraints, and enum members may come from __new__ and run __init__.

Inference and the language

  • Fields take their types from more expressions, such as and and or operands, comprehensions, module globals and other classes' attributes. Annotations read Literal[...], TypeGuard, TypeIs, TYPE_CHECKING imports and NewType. (alpha.1)
  • An int argument may reach a float parameter of a function called directly. Its body computes with int operations, as CPython's does, under Pystachy's 64-bit integer limits. (#1533)
  • Sequence patterns match lists, with starred names. Subscripts, slices, range() and % formatting ask objects for __index__(), %(name)s formats a mapping, and dict keys() and items() views act as sets in in and comparisons.
  • bytearray supports indexing, slicing, slice assignment and its in-place methods; library functions still take bytes. (#1478)

Standard library

  • New: pprint, inspect.Signature, subprocess over fork and exec, importlib.resources, importlib.metadata, sysconfig, platform, base64 and gc. concurrent.futures runs a ThreadPoolExecutor on the program's one thread. (library reference)
  • functools.cached_property and total_ordering, contextlib.ExitStack and modules' __file__ are available. decimal adds exp(), ln(), log10() and Decimal powers, rounded as libmpdec rounds them, and str case methods follow CPython's Unicode rules. (limits)

Testing and performance

  • The native pytest runner runs unittest.TestCase classes, layered conftest.py files, marks, -k and -m, fixture scopes and parameters, tmp_path, capsys, capfd and monkeypatch. (#1287)
  • str case methods and character tests read generated Unicode tables, taking 0.3 to 1.9 times CPython's time on Russian, Chinese and French text (measurements). Float powers, rounding, %, // and comparisons of ints with floats run inline.
  • As opt-ins, PYSTACHY_JIT_OPT=2 runs LLVM's -O2 pipeline in the JIT, and PYSTACHY_PROFILE_GENERATE and PYSTACHY_PROFILE_USE optimize an executable by its profile. The PYSTACHY_UNICODE_AUDIT setting is removed.

Correctness repairs

Programs that v0.5.0 compiled now do what CPython does:

  • == and != between a value of a union of classes and an object compare the object, by its class's __eq__ or by identity, where v0.5.0 could print False for equal objects. (fix)
  • x += y through a value typed with a base class calls the in-place method of the object's subclass. Where the results have no common type, the program is rejected. (#1538)
  • A dict lookup whose key's __eq__ removes and stores its entry again finds it where it moved, where v0.5.0 could write outside the dict. (#1580)
  • On Linux AArch64, the collector scans the registers saved above main's frame, where a live object could be freed. (#1553)
  • Host paths such as sys.prefix keep their non-ASCII characters and undecodable bytes, and with dynamic Any, ranges answer isinstance() and == as CPython does. (#1517, #1523, #1595)

Known limits

Dynamic Any and promoting integers remain experimental opt-ins. Known issues include reads of a builtin's name where a module global of that name is unbound (#1512), star imports from a module that binds __all__ inside try or if (#1513), an except clause's as name that an import bound (#1514), isinstance() of Any values that hold NamedTuple objects (#1581) and isinstance() tests against a second base class (#1602). The compatibility reference lists the documented deviations.

Mapping patterns, async, full native mypy and broad concurrency remain outside v0.6.0.

Platforms

Native archive Requirements
Linux x86-64 / AArch64 Ubuntu 24.04 or compatible glibc 2.39+ Linux; LLVM 18
macOS arm64 / x86-64 macOS 15+, Xcode Command Line Tools; LLVM 20

Archives and Docker run without Python; the hosted compiler needs Python 3.11+ and reports commit unknown when installed with pip. Full verification targets Linux x86-64 and ARM64 with CPython 3.13.16. Linux archives are not manylinux packages.

Release assets

Native compiler archives for Linux x86-64/AArch64 and macOS arm64/x86-64 are attached below, with their SHA-256 checksums in SHA256SUMS. They require LLVM 18 on Linux or LLVM 20 on macOS; see the installation instructions.

Docker image: dta67/pystachy:v0.6.0 for linux/amd64 and linux/arm64, with LLVM 18 included.

Source commit: 817c9cd9e8a638232a65adb916af39735e503282.