Skip to content

A PEP 604 annotation in a test file takes out whole matrix legs before anything runs, and is invisible on any interpreter above the floor #237

Closed

Description

@fdaviddpt

The class

A collection error — an exception raised while pytest imports a test module — takes out an entire matrix leg before a single test runs, and is invisible on any interpreter that happens to accept the syntax.

#236 hit it: project: str | None in a test helper. PEP 604 unions are evaluated at import in annotation position, so on 3.9 that is a TypeError during collection. All three 3.9 legs failed identically across macOS, ubuntu and Windows; the other nine were green; nothing on the failing legs ran at all. The local suite passed, because this machine's Python is 3.14.

The floor is real: 3.9 is in the matrix, so it is a supported interpreter, not a preference.

Why a guard rather than vigilance

The failure has three properties that together make it a bad thing to catch by attention:

  1. Invisible locally unless you happen to have the floor interpreter installed. The perf(config): read the merged config once, not once per key (20 → 16 spawns per tool call) #236 agent looked: no python3.9, no pyenv, no uv, no conda on this machine.
  2. Whole-leg, not per-test. One bad annotation in one file and the leg reports nothing about the other 1,000 tests — an absence that reads like a normal failure.
  3. Cheap to detect statically. An AST walk flags it on every interpreter in milliseconds, with no need to run anything on 3.9.

The #236 agent wrote exactly this walk as a throwaway to answer "is my error masking a second instance?" — it walked all 79 .py files and came back clean. It then declined to turn it into a test, on the grounds that I had said "fix the floor violation, nothing else". That was the right call about scope and the wrong outcome for the repo, which is why this is filed rather than dropped.

What the guard has to cover

The naive version — grep for | in annotations — produces false positives from prose and shell pipes inside docstrings, which is what the agent hit before switching to an AST walk. The real shape:

  • PEP 604 unions in every position Python evaluates at import: argument annotations, return annotations, and variable annotations, in files without from __future__ import annotations.
  • Plus isinstance() / issubclass() arguments — the future import does not rescue those, since they are ordinary runtime expressions rather than annotations. That exception is the part a hand-rolled check is most likely to miss.

Worth deciding rather than assuming: whether the guard covers scripts//pipeline/ as well as tests/, and whether it reads the floor from pyproject.toml's requires-python rather than hardcoding 3.9 — claude-supertool has a sibling guard (#577/#579) whose whole lesson was that a scanner's scope must match the defect's, and it scanned build/ and .venv/ and reported violations in code that was not ours. Check what that one does before designing this one.

And per this repo's own contract: a guard that cannot run must say so rather than passing quietly. An AST walk that finds no files to walk is not a clean result.

Provenance

Found by the agent implementing #232, which fixed its own violation, verified by AST walk that nothing else in the repo had the same construct, and proposed this without building it.

Activity

  1. added a commit that references this issue on Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions