topmark.diagnostic.model¶
topmark / diagnostic / model
Core diagnostic types and helpers for TopMark.
This module defines internal diagnostic primitives used throughout the project to report informational messages, warnings, and errors. These are intentionally separate from the public API schemas so that internal diagnostics can evolve without breaking external contracts.
Sections
DiagnosticLevel: severity levels with associated semantic style roles.Diagnostic: immutable structured diagnostic payload (level + message).DiagnosticStats: aggregated per-level counts.MutableDiagnosticLog: mutable per-context collection with helpers for adding and summarizing diagnostics.FrozenDiagnosticLog: immutable snapshot container for frozen contexts.
DiagnosticLevel ¶
Bases: str, Enum
Severity levels for diagnostics collected during processing.
Levels map to semantic style roles and are ordered by importance: ERROR > WARNING > INFO. This enum is internal; the public API exposes string literals.
role
property
¶
Return the semantic StyleRole for this diagnostic level.
Renderers may map this role to concrete styling (e.g., colors).
Diagnostic
dataclass
¶
Internal structured diagnostic with a severity level and message.
Note
This type is not part of the public API surface. Conversions to
DiagnosticEntry happen at the API boundary.
DiagnosticStats
dataclass
¶
Aggregated counts for diagnostics by severity level.
get ¶
Return the count for the given diagnostic level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
DiagnosticLevel
|
Diagnostic severity level to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The aggregated count for the requested diagnostic level. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/topmark/diagnostic/model.py
triage_summary ¶
Return a compact triage summary ordered by decreasing severity.
The summary is built from the aggregated per-level counts stored on this
object and is suitable for concise human-facing suffixes such as:
"1 error, 2 warnings".
The severity_threshold controls how far the summary descends:
DiagnosticLevel.ERROR: include only errorsDiagnosticLevel.WARNING: include errors and warningsDiagnosticLevel.INFO: include errors, warnings, and infos
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
severity_threshold
|
DiagnosticLevel
|
Lowest severity level that may be included;
default: |
INFO
|
Returns:
| Type | Description |
|---|---|
str
|
Compact triage summary string. Returns an empty string when no |
str
|
matching counts are present. |
Source code in src/topmark/diagnostic/model.py
MutableDiagnosticLog
dataclass
¶
Mutable collection of diagnostics.
It provides convenience helpers for adding diagnostics at a given level and exposes simple
aggregation helpers (stats, to_dict) for reporting.
from_iterable
classmethod
¶
Create a FrozenDiagnosticLog from an iterable of diagnostics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagnostics
|
Iterable[Diagnostic]
|
Existing diagnostics (e.g., from a frozen snapshot). |
required |
Returns:
| Type | Description |
|---|---|
MutableDiagnosticLog
|
A new |
MutableDiagnosticLog
|
containing the provided diagnostics. |
Source code in src/topmark/diagnostic/model.py
freeze ¶
add ¶
Add a diagnostic to the diagnostic log.
The diagnostic is appended to the context in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagnostic
|
Diagnostic
|
The diagnostic object. |
required |
Source code in src/topmark/diagnostic/model.py
add_info ¶
Add an info diagnostic to the diagnostic log.
The diagnostic is appended to the context in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The diagnostic message. |
required |
Source code in src/topmark/diagnostic/model.py
add_warning ¶
Add a warning diagnostic to the diagnostic log.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The diagnostic message. |
required |
Source code in src/topmark/diagnostic/model.py
add_error ¶
Add an error diagnostic to the diagnostic log.
The diagnostic is appended to the context in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The diagnostic message. |
required |
Source code in src/topmark/diagnostic/model.py
stats ¶
Return per-level counts for diagnostics in this log.
The returned DiagnosticStats object
can be used both for human summaries and for machine-readable reporting via to_dict.
Source code in src/topmark/diagnostic/model.py
has_info ¶
has_warning ¶
Return True if the MutableDiagnosticLog contains warning diagnostics.
has_error ¶
to_dict ¶
Return a JSON-friendly mapping of counts by severity.
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Mapping with keys |
dict[str, int]
|
reflecting the number of diagnostics at each level. |
Source code in src/topmark/diagnostic/model.py
FrozenDiagnosticLog
dataclass
¶
Immutable diagnostic container.
FrozenDiagnosticLog is the
immutable counterpart to
MutableDiagnosticLog.
It is intended for storing diagnostics on immutable snapshots where mutation
is not permitted.
compute_diagnostic_stats ¶
Return per-level counts for a sequence of diagnostics.
The returned DiagnosticStats object
can be used both for human summaries and for machine-readable reporting via to_dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagnostics
|
Iterable[Diagnostic]
|
the diagnostic log. |
required |
Returns:
| Type | Description |
|---|---|
DiagnosticStats
|
Per-level counts for diagnostics in this log. |
Source code in src/topmark/diagnostic/model.py
diagnostics_counts_to_dict ¶
Return a JSON-friendly mapping of counts by severity for any iterable.