What's new in TyPy 0.5¶
TyPy 0.5.0 was released on 2026-11-17. This page summarises what it changes for you as you write programs; the changelog lists every change, with the requirement and the decision record of each.
Summary¶
- C libraries are called through the standard
ctypesmodule, andtypy build --libbuilds a module as a C library. matchstatements and assignment expressions are accepted.- An instance that never leaves the function that makes it is made in the function's frame, and a project can name the allocator its program uses.
- Classes, dataclasses, generics and protocols accept much more of what CPython runs.
Calling C and building C libraries¶
A module that declares a library with ctypes.CDLL("name") and sets the
argtypes and restype of its functions at module level calls them
directly, with the library linked when the program is built (FFI-01 to
FFI-03). The scalar types of ctypes, objects with value, byref,
pointers, arrays and ctypes.Structure subclasses behave as in CPython.
Calling C through ctypes
shows each, and
Linking a library shows the
typy.toml settings that say where a library is and how it is linked
(FFI-04).
typy build --lib static and --lib shared build a module as a C
library with a C header, exporting the functions __all__ lists (CLI-09,
FFI-05). The library's files carry the release of its version (CLI-13),
and a Python binding with its stub comes beside them, so a Python program
calls the library too (FFI-08). See
Building a library.
New statements and expressions¶
matchstatements, with every kind of pattern and guards, as Matching values describes (CST-06). The warning W0401 names the members of the subject's type that no case matches (CST-07), and@dataclasswrites__match_args__(CLS-05).- Assignment expressions,
name := value, with CPython's scope in comprehensions (EXP-13); see Expressions.
Memory¶
An instance of a class of the program that never outlives the function
that makes it is made in the function's frame, with no allocator call
(MEM-03). The table [allocator] in typy.toml names the functions a
program allocates with, such as mimalloc's (MEM-08); see
Choosing the allocator.
Classes, generics and types¶
NotImplementedgives way to the other operand's method (CLS-21), and a class may define the in-place operator methods (CLS-20), takesliceobjects (CLS-23) and decide its truth with__bool__or__len__(CLS-24).- Dataclasses take
field(default_factory=...), hash when frozen, and take the optionsinit,repr,unsafe_hashandslots(CLS-15 to CLS-17, CLS-28). - A protocol is the type of a variable, an attribute or a container item (GEN-10, GEN-17). A class may derive from a copy of a generic class (GEN-08), a method of a generic class may have type parameters of its own (GEN-09), and generic functions and classes of another module are imported (GEN-07).
- The names
Optional,Union,List,Dict,Set,TupleandTypeoftypingare accepted in annotations (LIB-17),sys.version_infois a value of its own (LIB-16), and type aliases may come from another module, be declared inside a function or a class, and bound their type parameters (SMT-12).
Changes that may affect your programs¶
list.sortandsortedcompare the items CPython 3.15 compares, in its order, so a__lt__that prints or raises shows the same calls as under CPython (OI-27).- A module-level statement that can call a function or a class before the
import that binds it has run is E0306, as CPython raises
NameErrorthere (TYP-12). - A name an import binds to a function or a class that the module also defines or assigns is E0202 (STD-04).
import collectionsis E0206, as for any module TyPy does not provide (LIB-08).
The troubleshooting page explains each code and how to change the program.