topmark.core.merge¶
Merge and extraction helpers for TopMark configuration.
This module centralizes small, typed utilities used across TopMark for:
1) Overlay merges of optional values (e.g., "use override if provided, else keep current").
2) Extracting typed optional values from config mappings
(e.g., TOML tables), returning None when the key is absent.
These helpers intentionally avoid importing TopMark configuration models to
prevent type-check-time import cycles. They are safe to use in topmark.config,
topmark.pipeline, CLI code, and plugins.
Design principles:
- Absent keys should generally map to None (inherit), not to a default.
- Extraction helpers are conservative: invalid values return None so the caller
can decide whether to warn, error, or keep defaults.
overlay ¶
Return override when set, otherwise return current.
This is the core "last-wins overlay" primitive used throughout config merging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current
|
T | None
|
The current value (possibly inherited). |
required |
override
|
T | None
|
The overriding value (highest precedence). |
required |
Returns:
| Type | Description |
|---|---|
T | None
|
The override value if it is not |
Source code in src/topmark/core/merge.py
opt_bool ¶
Return an optional bool value from a mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tbl
|
Mapping[str, object] | None
|
Mapping (e.g., a parsed TOML table). If |
required |
key
|
str
|
Key to read. |
required |
Returns:
| Type | Description |
|---|---|
bool | None
|
|
bool | None
|
|
Notes
This mirrors TOML parsing behavior in TopMark today: values are coerced
via bool(...). If you later want stricter typing (only accept actual
booleans), introduce a strict_opt_bool() variant.
Source code in src/topmark/core/merge.py
opt_enum ¶
Return an optional Enum member from a mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tbl
|
Mapping[str, object] | None
|
Mapping (e.g., a parsed TOML table). If |
required |
key
|
str
|
Key to read. |
required |
enum_cls
|
type[E]
|
Enum class used to interpret the value. |
required |
Returns:
| Type | Description |
|---|---|
E | None
|
|
E | None
|
|
E | None
|
|
Examples: