DiagnosticCollector

class DiagnosticCollector(_items: list[Diagnostic] = <factory>)[source]

Bases: object

Mutable accumulator for Diagnostic records produced during one stub-generation run.

A fresh instance is created inside every StubContext and passed through the pipeline so every stage can record issues without raising exceptions.

_items

Internal ordered list. Use the public properties to access it.

Type:

list of Diagnostic

Examples

>>> collector = DiagnosticCollector()
>>> collector.warning(DiagnosticStage.EMIT, "Foo.bar", "No return annotation")
>>> collector.has_warnings()
True
>>> len(collector)
1
add(level: DiagnosticLevel, stage: DiagnosticStage, symbol: str, message: str) None[source]

Append a diagnostic record.

Parameters:
info(stage: DiagnosticStage, symbol: str, message: str) None[source]

Convenience wrapper — records an INFO diagnostic.

warning(stage: DiagnosticStage, symbol: str, message: str) None[source]

Convenience wrapper — records a WARNING diagnostic.

error(stage: DiagnosticStage, symbol: str, message: str) None[source]

Convenience wrapper — records an ERROR diagnostic.

property all: list[Diagnostic]

Return a copy of all recorded diagnostics in order.

property warnings: list[Diagnostic]

Return all WARNING diagnostics.

property errors: list[Diagnostic]

Return all ERROR diagnostics.

property infos: list[Diagnostic]

Return all INFO diagnostics.

has_errors() bool[source]

Return True if any ERROR was recorded.

has_warnings() bool[source]

Return True if any WARNING was recorded.

by_stage(stage: DiagnosticStage) list[Diagnostic][source]

Return all diagnostics from stage.

by_symbol(symbol: str) list[Diagnostic][source]

Return all diagnostics whose symbol field equals symbol.

summary() str[source]

Return a human-readable summary line.

Examples

>>> c = DiagnosticCollector()
>>> c.summary()
'0 errors, 0 warnings, 0 infos'
format_all() str[source]

Return all diagnostics joined by newlines, suitable for printing.

clear() None[source]

Remove all recorded diagnostics.

__init__(_items: list[Diagnostic] = <factory>) None

See also

Public API reference — overview of all public names.