Skip to content

comicbox.readinglists.changes ΒΆ

Name what a load dropped or changed, by comparing its input and output.

One mechanism for every kind of loss: an unknown key, an invalid value, a structure where a scalar belongs, a clamped number. A value equal in meaning, such as 1 read as "1", Event read as event or a list of tags read as a set, is not a change.

describe_changes(raw, loaded, path='', ignore=_NO_IGNORE) ΒΆ

Name every key or value in raw that loaded dropped or changed.

path prefixes each message; list items are numbered from 1. ignore names keys a format leaves out on purpose.

Source code in comicbox/readinglists/changes.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
def describe_changes(
    raw: Any, loaded: Any, path: str = "", ignore: frozenset[str] = _NO_IGNORE
) -> Iterator[str]:
    """
    Name every key or value in ``raw`` that ``loaded`` dropped or changed.

    ``path`` prefixes each message; list items are numbered from 1.
    ``ignore`` names keys a format leaves out on purpose.
    """
    if isinstance(raw, Mapping):
        yield from _mapping_changes(raw, loaded, path, ignore)
    elif isinstance(raw, list | tuple) and isinstance(loaded, set | frozenset):
        yield from _set_changes(raw, loaded, path)
    elif isinstance(raw, list | tuple) and isinstance(loaded, list | tuple):
        yield from _list_changes(list(raw), list(loaded), path, ignore)
    elif isinstance(raw, list | tuple) and len(raw) == 1:
        yield from describe_changes(raw[0], loaded, path, ignore)
    elif not _same(raw, loaded):
        yield f"{path}: {_repr(raw)} read as {_repr(loaded)}"

quote_value(value) ΒΆ

Quote a value for a warning, cut to a bounded length; a date as ISO text.

Source code in comicbox/readinglists/changes.py
33
34
35
36
def quote_value(value: Any) -> str:
    """Quote a value for a warning, cut to a bounded length; a date as ISO text."""
    text = value.isoformat() if isinstance(value, date) else _REPR.repr(value)
    return text if len(text) <= _MAX_REPR else text[: _MAX_REPR - 1] + "…"