topmark.toml.typing_guards¶
topmark / toml / typing_guards
Type guards and TOML-shape normalization helpers for TopMark TOML handling.
This module provides TypeGuard-based predicates that help Pyright narrow
runtime values coming from TOML parsing, including tomlkit objects.
It focuses on: - recognizing plain-Python TOML-compatible shapes - normalizing parsed objects into the recursive TOML table aliases used across TopMark - narrowing nested TOML table mappings such as grouped subtable collections
See Also:
- topmark.core.typing_guards: generic type guards and normalization
helpers for parsing weakly typed objects.
- topmark.toml.utils: small builders and normalization
helpers for TOML-compatible values and tables.
is_toml_table ¶
Type guard for a TOML table-like mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
Value to test. |
required |
Returns:
| Type | Description |
|---|---|
TypeGuard[TomlTable]
|
|
Source code in src/topmark/toml/typing_guards.py
is_toml_value ¶
Return whether value conforms to the recursive TomlValue shape.
Source code in src/topmark/toml/typing_guards.py
toml_table_from_mapping ¶
Return a validated TOML table copied from a generic mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, object]
|
The mapping to convert. |
required |
Returns:
| Type | Description |
|---|---|
TomlTable
|
TomlTable representation of |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the mapping contains a value that is not representable as |
Source code in src/topmark/toml/typing_guards.py
is_tomlkit_table ¶
Type guard for a tomlkit.items.Table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
Value to test. |
required |
Returns:
| Type | Description |
|---|---|
TypeGuard[Table]
|
|
Source code in src/topmark/toml/typing_guards.py
as_toml_table ¶
Return the object as a TOML table when possible.
A TOML table is represented by the recursive TomlTable alias used across
TopMark TOML handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
Arbitrary object obtained from parsed TOML. |
required |
Returns:
| Type | Description |
|---|---|
TomlTable | None
|
|
Source code in src/topmark/toml/typing_guards.py
as_toml_table_map ¶
Return a mapping of string keys to TOML subtables.
This helper is useful for normalizing nested sections like [policy_by_type]
where each value must itself be a TOML table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
Arbitrary object obtained from parsed TOML. |
required |
Returns:
| Type | Description |
|---|---|
TomlTableMap
|
A mapping with only |
TomlTableMap
|
are silently dropped. |