topmark.processors.types¶
topmark / processors / types
Type definitions for the pipeline processing layer.
This module provides structured type definitions, such as dataclass objects, used to pass data between the pipeline's distinct phases. These types improve the clarity and type safety of complex return values compared to using bare tuples or dictionaries.
HeaderParseResult
dataclass
¶
Result of parsing key-value fields from a header block.
This dataclass provides a structured and type-safe alternative to a bare return tuple, ensuring that consuming code can access the parsed data and metrics by name. The initializer requires all arguments to be passed by keyword.
Attributes:
| Name | Type | Description |
|---|---|---|
fields |
dict[str, str]
|
Mapping of all successfully parsed header fields (key → value). Defaults to an empty dictionary. |
success_count |
int
|
The number of header lines that were successfully parsed and added to the
|
error_count |
int
|
The number of header lines that were malformed (e.g., missing a colon, or having an empty field name). Defaults to 0. |
BoundsKind ¶
Bases: Enum
Discriminant for header-bound detection results.
Members
SPAN: A valid header span was found.
MALFORMED: Header markers exist, but their shape is invalid (e.g., only end,
only start, multiple starts/ends, or end before start).
NONE: No header markers were detected.
HeaderBounds
dataclass
¶
Structured result for header-bound detection.
This is a discriminated union controlled by kind:
- When
kind is BoundsKind.SPAN:startandendare required (0-based line indexes).startis inclusive,endis exclusive (slice-friendly).reasonis unused (None).
- When
kind is BoundsKind.MALFORMED:start/endMAY be provided to pinpoint the offending region (best-effort; if unknown, they can beNone).reasonSHOULD explain the malformed shape (e.g.,"end without start").
- When
kind is BoundsKind.NONE:- No markers were detected;
start/end/reasonareNone.
- No markers were detected;
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
BoundsKind
|
Discriminant of the result. |
start |
int | None
|
Start line index (inclusive) when a span is available. |
end |
int | None
|
End line index (exclusive) when a span is available. |
reason |
str | None
|
Human-readable reason when |
StripDiagKind ¶
Bases: Enum
Outcome classification for header stripping operations.
Members
REMOVED: A header was found and removed successfully. NOT_FOUND: No header was detected; no changes made. MALFORMED_REFUSED: Malformed header markers detected; removal refused by policy. MALFORMED_REMOVED: Malformed markers detected but removal performed (if policy allows). NOOP_EMPTY: File effectively empty; nothing to remove. ERROR: Unexpected error encountered; no changes made.
StripDiagnostic
dataclass
¶
Diagnostic payload describing a strip attempt.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
StripDiagKind
|
High-level outcome classification. |
reason |
str | None
|
Optional human-readable explanation (e.g., policy gate or malformed reason). |
removed_span |
tuple[int, int] | None
|
Inclusive (start, end) span of the removed header in the original input; present only when a header was actually removed. |
notes |
list[str]
|
Additional details for logging or user-facing hints. |
StripHeaderResult
dataclass
¶
Result of attempting to remove a TopMark header from file lines.
Attributes:
| Name | Type | Description |
|---|---|---|
lines |
list[str]
|
Updated file lines. This is the original line list when no header was removed or when removal was refused. |
removed_span |
tuple[int, int] | None
|
Inclusive |
diagnostic |
StripDiagnostic
|
Diagnostic payload describing the strip attempt outcome. |