misc
CheckKeyDuplicatesYamlLoader
Bases: SafeLoader
YAML loader that detects duplicate keys and either warns or raises an error. Also tracks line numbers for values to enable better error reporting.
Source code in src/sparkwheel/utils/misc.py
construct_object(node, deep=False)
Construct object and attach source location metadata.
Source code in src/sparkwheel/utils/misc.py
check_key_duplicates(ordered_pairs)
Checks if there is a duplicated key in the sequence of ordered_pairs.
If there is - it will log a warning or raise ValueError
(if configured by environmental var SPARKWHEEL_STRICT_KEYS==1)
Otherwise, it returns the dict made from this sequence.
Note: This function is kept for compatibility but is primarily used by the YAML loader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ordered_pairs
|
list[tuple[Any, Any]]
|
sequence of (key, value) |
required |
Source code in src/sparkwheel/utils/misc.py
ensure_tuple(vals)
Returns a tuple of vals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vals
|
Any
|
input data to convert to a tuple. |
required |
first(iterable, default=None)
Returns the first item in the given iterable or default if empty.
issequenceiterable(obj)
Determine if the object is an iterable sequence and is not a string.