aython

Chapter 10 of 1113 min read

Measuring against the real world

How many files of CPython's own standard library the subset accepts as they are, and what each new construct moved.

The corpus in tests/mvp/ was written for the subset, so it can only show that the subset works on programs shaped for it. The stdlib census asks a harder question: of the Python files CPython itself ships, written by people who never heard of aython, how many does the frontend accept as they are? The answer is small, and the way it moves, slice by slice, says more about the subset than any count of supported features.

The latest recorded figure is 31 of 637 files (4.9%), up from 18 (2.8%) at the first measurement. CI fails any change that takes the count below 31.

What is measured #

aython stdlib-census walks a directory of Python files, by default the running interpreter’s own standard library, and asks the frontend about each one. The whole classification is one function:

src/aython/stdlib.py · census_filelines 49–70def census_file(path: Path) -> str:
    """Classify one file as accepted or by its first blocking construct.

    Args:
        path: Candidate ``.py`` file to validate.

    Returns:
        ``ACCEPTED_BUCKET`` when the frontend admits the file, else the
        feature string from :func:`feature_of`. Unreadable files report
        as ``unreadable`` instead of aborting the census.
    """
    try:
        source = path.read_text(encoding=READ_ENCODING, errors="replace")
    except OSError:
        return "unreadable"
    try:
        compile_source(source, str(path))
    except FrontendError as exc:
        return feature_of(exc)
    except SyntaxError:
        return SYNTAX_BUCKET
    return ACCEPTED_BUCKET

Three things about it decide what the numbers mean.

Accepted means compiled, nothing more. A file is accepted when compile_source returns without raising: it parses, every construct is inside the subset, and every import it makes can be resolved and is itself inside the subset. Nothing is assembled, nothing runs, and no output is compared with CPython. The census is a measure of reach, not of correctness; correctness is the judge’s job, on the corpus.

Each refused file votes once, for its first wall. The frontend stops at the first construct it refuses (see From source to a checked program), and feature_of keeps the text after unsupported: in that message:

src/aython/stdlib.py · feature_oflines 32–46def feature_of(error: FrontendError) -> str:
    """Extract the blocking feature name from a frontend refusal.

    Args:
        error: The ``FrontendError`` raised by ``compile_source``.

    Returns:
        The text after ``unsupported: ``, or the whole message when the
        refusal carries no feature tail (e.g. syntax errors).
    """
    msg = str(error)
    marker = "unsupported:"
    if marker in msg:
        return msg.split(marker, 1)[1].strip()
    return msg[:80]

So the histogram the command prints counts first blockers. A file that uses import, default arguments and classes is counted once, under whichever the frontend meets first. Deeper walls stay invisible until the shallow ones fall, which is why a slice can remove a whole category from the histogram without accepting a single new file.

Imports must close. census_file passes the file’s real path, and the frontend resolves import m against the importing file’s own directory (_expand_imports in frontend.py). An importing file is accepted only if every module it pulls in is found there and is itself accepted. Most of the standard library imports sys, os or a C extension such as _abc, none of which exists as a sibling .py file, so imports are a wall that subset work alone cannot remove.

flowchart LR
  f["one stdlib .py file"] --> cs["compile_source(source, path)"]
  cs -->|"returns"| acc["accepted"]
  cs -->|"FrontendError"| fb["feature_of: text after unsupported:"] --> hist["first-blocker histogram"]
  cs -->|"imports"| sib["sibling .py files, compiled the same way"] --> cs
  class cs accent
  class acc good
What the census does with each file. Nothing after the frontend runs: no assembler, no executable, no CPython oracle.

Which tree, which CPython #

The default root is sysconfig.get_path("stdlib"), the standard library of whatever CPython runs the command (default_stdlib in stdlib.py), and the report names that version on its first line. The recorded figures are for CPython 3.14, whose tree the log describes as 637 files.

Numbers compare only within one version, because each CPython release adds, removes and rewrites files. They also compare only within one tree: the census counts every *.py file under the root, recursively, so an installation that keeps its test suite or third-party packages under the same directory measures a different and much larger tree with the same version number. A count from another machine is a different measurement, not a regression.

--stdlib DIR measures any other directory, and --out FILE writes the Markdown report (default build/stdlib-census.md, which is not committed):

uv run aython stdlib-census                         # this CPython's stdlib, report in build/
uv run aython stdlib-census --stdlib path/to/Lib    # another tree
uv run aython stdlib-census --min-accepted 31      # what CI runs: fail below the floor

The floor in CI, and why a floor #

The census runs on every push and pull request, as one step of .github/workflows/ci.yml, which runs the command with --min-accepted 31. The command exits non-zero when fewer files than that are accepted:

src/aython/cli.py · stdlib_censuslines 272–308@app.command()
def stdlib_census(
    stdlib: Path | None = typer.Option(None, help="Stdlib root to measure (default: running interpreter's)."),
    out: Path | None = typer.Option(None, help="Write the Markdown report here (default: build/stdlib-census.md)."),
    min_accepted: int = typer.Option(0, help="Fail when fewer than this many files are accepted (regression floor)."),
    verbose: bool = typer.Option(False, help="Debug logging."),
) -> None:
    """Measure how much of a stdlib tree the frontend accepts.

    Args:
        stdlib: Root to search recursively; defaults to the running
            interpreter's own standard library.
        out: Report destination; defaults into build/.
        min_accepted: Exit non-zero below this accepted count, so CI
            catches subset regressions.
        verbose: Enable debug logging.

    Returns:
        Nothing; exits 0 after writing the report.
    """
    configure_logging(verbose)
    root = stdlib or stdlib_mod.default_stdlib()
    if not root.is_dir():
        log.error("stdlib root not found: %s", root)
        raise typer.Exit(EXIT_FAIL)
    report = stdlib_mod.census_dir(root)
    for feature, count in report["blockers"].most_common(10):
        log.info("%4d  %s", count, feature)
    log.info("accepted %d/%d files", report["accepted"], report["files"])
    dest = out or (Path.cwd() / "build" / "stdlib-census.md")
    dest.parent.mkdir(parents=True, exist_ok=True)
    dest.write_text(stdlib_mod.render_markdown(report), encoding="utf-8")
    log.info("wrote %s", dest)
    if report["accepted"] < min_accepted:
        log.error("accepted %d below floor %d", report["accepted"], min_accepted)
        raise typer.Exit(EXIT_FAIL)
    raise typer.Exit(EXIT_OK)

It is a floor, not an exact count, on purpose:

Alternative What would go wrong
No check at all A change that tightens a refusal, or breaks import resolution, could quietly un-accept stdlib files; the corpus would not notice, because its programs are shaped for the subset
An exact count The test would fail whenever the runner’s CPython is updated and its tree changes by a file, which says nothing about aython
A floor Fails only on a loss; a slice that raises the count raises the floor in the same pull request, so the gain cannot later be lost unnoticed

The floor is a ratchet: it only moves up, and only by hand, in the change that earned it. It says nothing about which files are accepted. If one file were lost and another gained in the same change, the count, and so the check, would not move.

The numbers, slice by slice #

docs/stdlib-census.md is the durable record: one entry per slice that changed the subset, with the count after it. The figure is drawn from that log at build time; the site’s build does not run the census.

Files of the CPython 3.14 standard library the frontend accepts, after each slice in the census log, with the CI floor. Point at a slice, or tab to the chart and use the arrow keys, to read what it changed. Switch to "Only slices that moved it" to see the 9 that raised the count.
Logged Slice Change Accepted CI floor
Baseline (CPython 3.14, main at the emitter slice) 18/637 (2.8%)
2026-11-28 docstrings skipped +4 22/637 (3.5%) 22
2026-11-28 annotations ignored +1 23/637 (3.6%) 23
2026-11-28 flexible signatures +0 23/637 (3.6%) 23
2026-11-28 imports +2 25/637 (3.9%) 25
2026-11-28 minimal classes +0 25/637 (3.9%) 25
2026-11-28 relative imports +0 25/637 (3.9%) 25
2026-11-28 cross-module classes +0 25/637 (3.9%) 25
2026-11-28 in-function imports +0 25/637 (3.9%) 25
2026-11-29 dotted imports +0 25/637 (3.9%) 25
2026-11-29 try-else +0 25/637 (3.9%) 25
2026-11-29 remaining augassign +0 25/637 (3.9%) 25
2026-11-29 single-inheritance class bases +0 25/637 (3.9%) 25
2026-11-30 list slice stores +0 25/637 (3.9%) 25
2026-11-30 builtin-exception class bases +0 25/637 (3.9%) 25
2026-11-30 plain self-imports as no-ops +0 25/637 (3.9%) 25
2026-11-30 class-level constant values + class-body pass +0 25/637 (3.9%) 25
2026-11-30 __slots__ as ignored no-ops +0 25/637 (3.9%) 25
2026-11-30 multiple inheritance via C3 MRO +0 25/637 (3.9%) 25
2026-11-30 NotImplementedError as kind 11, EOFError as erased base +1 26/637 (4.1%) 26
2026-11-30 multi-target assignment +1 27/637 (4.2%) 27
2026-11-30 raise Name / Name(…) as evaluate-then-abort TypeError +1 28/637 (4.4%) 28
2026-11-30 scalar builtins chr/ord/isinstance +1 29/637 (4.6%) 29
2026-11-30 chained comparisons +1 30/637 (4.7%) 30
2026-11-30 repr() builtin +1 31/637 (4.9%) 31

What moved it, and what did not #

At the baseline, the first walls were these (the log’s table, the files whose first refusal was each construct):

First blocker at the baseline Files
bare expression, mostly docstrings (only calls allowed) 206
def argument defaults 152
import statement 114
starred *args / keyword-only args 84
annotations / decorated def 45
async def, classes, misc 16

Of the 24 slices logged since, 9 raised the count and 15 left it where it was.

The slices that raised it: docstrings skipped (+4); annotations ignored (+1); imports (+2); NotImplementedError as kind 11, EOFError as erased base (+1); multi-target assignment (+1); raise Name / Name(…) as evaluate-then-abort TypeError (+1); scalar builtins chr/ord/isinstance (+1); chained comparisons (+1); repr() builtin (+1).

Three patterns are visible in the log.

The cheap, shallow slices came first and paid at once. Skipping docstrings removed the commonest first wall outright, because a module’s docstring is usually its first statement: a small change to the frontend, and every file whose only problem was its docstring was accepted. Ignoring annotations did the same on a smaller scale.

The later gains are single files with nothing else in the way. The files that each later slice accepted are small modules of constants, simple functions and plain classes: the log names xml/dom/NodeFilter.py for NotImplementedError as a raise kind, tkinter/constants.py for multi-target assignment, xml/sax/handler.py for raise Name, and curses/ascii.py for chained comparisons. A file joins the count only when its last wall falls, and for most of the library that last wall is an import of a module with no .py source.

The slices that held the count still moved the wall. Flexible signatures changed the calling convention (defaults, *args, keyword-only parameters, **kwargs) and accepted no new file: the log records that the files they freed piled up behind import, which became the top wall. Imports then accepted few files, because of the closure rule above, and turned the histogram into a list of missing C-extension and platform modules. Classes, inheritance, try-else and slice stores each dissolved a small wall into the next one. That is the census working as intended: the log’s Method section says that re-running it after each slice “shows the wall moving, which is the point”.

What the census does not say #

  • That accepted files run correctly. Nothing is executed. An accepted file may abort at run time, or print something CPython would not, wherever the subset’s semantics differ (see Where it differs from CPython).
  • How useful the subset is. The standard library is a hard target by design: it is written against the full language and leans on C extensions. A low percentage is the expected result, and the trend is the signal.
  • Anything about deeper walls. The histogram ranks first blockers only. A wall can only be seen once every wall in front of it is gone.
  • Today’s exact figure on your machine. The build quotes the last logged entry. Run the command for a current count, and compare it only with counts from the same tree.

Where this lives #

Concept Where
Classifying one file src/aython/stdlib.py census_file, feature_of
Walking a tree, the report src/aython/stdlib.py census_dir, render_markdown, default_stdlib
The command and the floor src/aython/cli.py stdlib_census (aython stdlib-census, --min-accepted)
What “accepted” runs src/aython/frontend.py compile_source, _expand_imports, FrontendError
The floor CI enforces .github/workflows/ci.yml, the stdlib-census --min-accepted step
The log of slices docs/stdlib-census.md
This page’s data docsite/figures/census.py, docsite/figures/census_log.py

Check yourself #

Check yourself

  1. The census marks a stdlib file as accepted. What has been checked about it?

    1. It compiles, runs and prints what CPython prints
    2. The frontend’s compile_source raised nothing for it and for every module it imports
    3. It parses with ast
    4. It assembles and links with runtime.s
    AnswerThe frontend’s compile_source raised nothing for it and for every module it imports. census_file calls compile_source and counts the file as accepted when no FrontendError comes out. Nothing is assembled or run, and no output is compared.
  2. A file uses default arguments on line 10 and import sys on line 2. Which blocker does it count under?

    1. Both
    2. Default arguments, the more common one
    3. Whichever the frontend refuses first; here the import, which it meets first
    4. Neither: files with two blockers are skipped
    AnswerWhichever the frontend refuses first; here the import, which it meets first. Each refused file votes once, for the construct named in the first FrontendError. Imports are expanded before the rest is checked, so a missing sys refuses the file before line 10 is looked at.
  3. A slice adds a construct that 40 stdlib files use, and the accepted count does not change. What is the likeliest reading?

    1. The slice is broken
    2. Those files had other, deeper walls behind this one; the histogram should show them moving to their next blocker
    3. The census only counts files without imports
    4. CI’s floor stopped the count from rising
    AnswerThose files had other, deeper walls behind this one; the histogram should show them moving to their next blocker. A file joins the count only when its last wall falls. The log is full of +0 slices that moved files from one first blocker to the next, such as flexible signatures piling files onto the import wall.
  4. Why does CI check a floor (--min-accepted N) rather than the exact count?

    1. Exact counts are slow to compute
    2. A floor fails only on a loss, survives the runner’s stdlib changing under it, and is raised by hand when a slice earns more
    3. The count is random
    4. The census cannot report an exact count
    AnswerA floor fails only on a loss, survives the runner’s stdlib changing under it, and is raised by hand when a slice earns more. The floor is a ratchet against regressions. An exact count would fail on unrelated changes to the CPython tree; no check at all would let a tightened refusal un-accept files silently.