Skip to content

Add ellipsis when shortening dicts in locals #490

@maltherd

Description

@maltherd

Suggestion: rewrite the relevant function as

def shorten_mapping(obj: Union[dict, Mapping], max_keys: int) -> dict:
    if len(obj) <= max_keys:
        return obj

    return  {
        **{k: obj[k] for k in itertools.islice(obj.keys(), max_keys)},
        "...": "..."
    }

The ordering is not preserved, but that's ok given the default size is 10.
For a developer reading logs, it is imperative to know whether truncation took place.

Thanks

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions