Browse the documentation

Conformance tests

The test suite that compares Typhon's output with CPython's, byte for byte, and its current results.

CPython is the reference for Typhon’s behaviour. Every conformance case is a small program in tests/conformance/cases that covers one area. Each case is valid Python, and tests/conformance/expected holds what CPython 3.15 printed for it. A case passes when Typhon’s output matches that file byte for byte.

Areas covered

The 656 cases cover arithmetic, 64-bit and big integers, strings and format specifications, containers, dict semantics and order, control flow and exceptions, for ... else, functions and generators, classes and protocol methods, printing, async, type inference, code without annotations, late-bound values, and NumPy. Newer cases cover the standard library data modules (heapq, bisect, copy, json, re, io, array, frozenset), binary data (bytes, bytearray, struct, hashlib), the generator protocol with send, throw, close and return values, __dict__, functions as values, % formatting and class hierarchies, named tuples, **kwargs, tuples as sequences and classes defined in functions. The newest cases cover decorators and context managers, the remaining forms of generators, late-bound values as larger programs use them, getattr and setattr, sys.exit, multiple inheritance and mixins, overloads from inferred calls, idioms of CPython’s own modules, numpy.linalg, attributes set from outside a class, subclasses of the runtime’s classes, modules and classes as values, newer syntax such as lazy imports, template strings and type aliases, builtin types as values, forms that CPython’s standard modules use, unittest, pdb, compile, exec and eval, f(**opts), and standard library modules such as asyncio, datetime, csv, argparse, logging, os, sys, io, threading, weakref and warnings. Later cases cover abstract base classes and mixins, union and generic alias values, slice and super objects, contextlib.ExitStack, importlib module specs and runpy, profiling events, gzip and bz2 readers, possessive quantifiers in re, TCP sockets and select over the loopback interface, class bodies that run in definition order, classes defined in conditional branches, ast and tokenize at runtime, marshal, functools.singledispatch, big integers in ranges and byte conversions, async generators and asynchronous iteration, delegation with yield from, UDP sockets, traceback with source positions, Unicode data and grapheme segmentation, importlib.resources readers, pickle data exchanged with CPython, gettext and locale, the state of random, ast.literal_eval, codecs such as raw_unicode_escape, more operations on big integers, exception notes, sys.settrace and sys.monitoring events, generic classes in the older Generic[T] form, ast.NodeTransformer, .pyc headers and source loaders, zlib streams, handlers installed with signal, opcode metadata, the CPython modules that Typhon ships as source, modules selected with #:pylib-source such as pickle, gzip and dataclasses, subprocess pipes and codec error handlers. GDScript has a suite of its own, with Godot as the reference.

Running the suite

dotnet test tests/Typhon.Conformance.Tests

This compiles and runs every case with typhon run and compares the output. Setting TYPHON_CONFORMANCE_AOT=1 also builds every case with --aot and runs the native executable:

TYPHON_CONFORMANCE_AOT=1 dotnet test tests/Typhon.Conformance.Tests

After a case changes, python tests/conformance/update_expected.py regenerates the expected output with CPython.

Safeguards

The suite runs every case under CPython as well, so an outdated .out file fails the build. The test project finds CPython through TYPHON_CPYTHON, the repository’s .venv or the PATH. Without CPython, the check of the expected outputs against CPython passes with a note, unless TYPHON_REQUIRE_CPYTHON=1 is set, as it is in CI.

tests/conformance/known-failures.txt lists the cases that are known to differ from CPython, each with its reason. Such a case must keep failing. When a fix makes it pass, the suite fails until the line is removed.

The CI workflow runs the suite on Windows and Linux for every push to main and every pull request. The Native AOT pass is started by hand.

Current results

RunResult
typhon run654 of 656 cases match CPython.
Native AOTThe last full pass ran when the suite had 17 cases. 10 of them built and matched as native executables. arithmetic, inference, loop_else and numpy_basics use dynamic values, which Native AOT rejects.

Two cases are known failures:

  • numpy_details fails because a.shape is not a tuple, stepped slices of an ndarray are not supported, and a boolean array sums to a float.
  • int_overflow fails because an int beyond 64 bits raises OverflowError in the default mode, where CPython switches to arbitrary precision. The case bigint_mode tests big-int mode, which makes int unbounded.

Differences the suite found

Writing the suite revealed differences from CPython that were then fixed: inherited constructors of an Exception subclass without __init__, sorted() over objects with __lt__, Color.RED.value and .name, type(x).__name__, try/except/else in functions that return a value, except ValueError catching an IndexError, iterating over a dict, d.get(k) without a default, del, the g format and the float repr (1e+16), and built-in functions as values (map(str, xs), key=len). Before int became 64-bit, Typhon printed 704982704 for sum(range(100000)), where the correct result is 4999950000.

The Native AOT pass found two more: len() of a class with __len__ and the repr of a set relied on reflection that Native AOT trims away.