Repository navigation
Pystachy v0.6.0
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 ofCor a subclass in variables, fields and containers. Class objects answerisinstance()andissubclass(), construct objects and call class and static methods;type[object]also holds builtin classes such asint. (alpha.2)- A union may hold
int,float,boolorstrbeside objects of the program's classes, and runtime-length tuples hold objects.isinstance(),callable(),Noneand truth tests ofx.anarrow 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[...].TypeVartakes 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
andandoroperands, comprehensions, module globals and other classes' attributes. Annotations readLiteral[...],TypeGuard,TypeIs,TYPE_CHECKINGimports andNewType. (alpha.1) - An
intargument may reach afloatparameter of a function called directly. Its body computes withintoperations, 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)sformats a mapping, and dictkeys()anditems()views act as sets ininand comparisons. bytearraysupports indexing, slicing, slice assignment and its in-place methods; library functions still takebytes. (#1478)
Standard library
- New:
pprint,inspect.Signature,subprocessover fork and exec,importlib.resources,importlib.metadata,sysconfig,platform,base64andgc.concurrent.futuresruns aThreadPoolExecutoron the program's one thread. (library reference) functools.cached_propertyandtotal_ordering,contextlib.ExitStackand modules'__file__are available.decimaladdsexp(),ln(),log10()andDecimalpowers, rounded as libmpdec rounds them, andstrcase methods follow CPython's Unicode rules. (limits)
Testing and performance
- The native pytest runner runs
unittest.TestCaseclasses, layeredconftest.pyfiles, marks,-kand-m, fixture scopes and parameters,tmp_path,capsys,capfdandmonkeypatch. (#1287) strcase 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=2runs LLVM's -O2 pipeline in the JIT, andPYSTACHY_PROFILE_GENERATEandPYSTACHY_PROFILE_USEoptimize an executable by its profile. ThePYSTACHY_UNICODE_AUDITsetting 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 printFalsefor equal objects. (fix)x += ythrough 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.prefixkeep their non-ASCII characters and undecodable bytes, and with dynamicAny, ranges answerisinstance()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.