ADR-0017: Results Have a One-Line Repr and Print as a Summary#

Status#

Accepted 2026-12-02

Context#

Printing a result is the first thing its reader does with it, whether the reader is a person at a REPL, a script’s log, or an agent running code for a user. irtlib’s results were dataclasses whose generated repr printed every array in full. A 2PL calibration of 40 items printed 18,182 characters on 415 lines without an item name, and its item fit printed 2,868 characters. No class defined __str__, so print() showed the same text.

Python’s data model gives the two forms different jobs. __repr__ is the “official” form, used for debugging, so it is information-rich and unambiguous. __str__ is the “informal”, nicely printable form that print() and format() use (Python Language Reference, “Data model”, object.__repr__ and object.__str__).

Decision#

  • The repr is one line: the class and the sizes and values that describe the object, such as ItemBank(n_items=40, model=2PL) or Calibration(likelihood=marginal, items=ItemBank(n_items=40, model=2PL), converged=True, cycles=29).

  • The printed form is a summary for the types with per-item or per-examinee arrays: the bank, calibrations, ability estimates, the number-correct estimates, item fit and the mean squares. The other types print their repr.

  • A summary is a map of its object, so that what a reader sees tells them where the rest is:

    • each attribute listed, and each table’s caption, is an attribute’s name as the code spells it;

    • a table’s columns are attributes holding one value per row, or the columns of one: the parameters a, b, c and d of an item matrix, their standard errors se(a) to se(d), and the items’ names;

    • every row of the table shows its index and, where the object has one, its name;

    • problems are named before the table: converged is a calibration’s first attribute, its items line names the items its bank leaves out, and the examinees estimated by the fallback or with warnings are named above their table;

    • a table of more than 30 rows prints its first and last five, and counts the rows between them;

    • a last line names the arrays not shown, with their shapes;

    • a guessing parameter of 0 and an upper asymptote of 1 for every item get no column, and a note says so.

  • irtlib formats the numbers itself, with Python’s format specifications, so the text is the same on every NumPy version.

  • The layout is not part of the call contract. Programs read the attributes. A docstring says what the printed form shows, not how it is laid out.

  • One private module, irtlib._text, writes every summary.

Consequences#

  • From print() alone, a reader learns the attributes’ names and where the data not shown lives.

  • Every field of a result type appears in its printed form, and a test checks this, so a field added to a result type must be placed in its summary.

  • A result type that subclasses another, like MCMCCalibration, declares its dataclass with repr=False. Otherwise the decorator generates a repr of every field, over the parent’s one line.

  • The layout can change in any release, since it is not part of the contract.

Alternatives Considered#

  • The table as the repr, as pandas prints its data frames: a nested object’s repr would span lines inside its parent’s, and in test failures and logs.

  • A summary() method: a reader would first have to know that it exists, while print() is what people and agents type first.

  • NumPy’s print options for the cut and the precision: the text would change with NumPy’s version, and with options set elsewhere in the session.

  • An HTML form for notebooks: left to the tutorial notebooks, when they are written.