Skip to content

Add sort_dicts parameter to reprlib.Repr #155812

Description

@warden127

Feature or enhancement

Proposal:

reprlib.Repr currently sorts dictionaries by key when producing representations. However, sometimes the insertion order is meaningful. It would be useful to have a sort_dicts parameter, analogous to the existing parameter in pprint.PrettyPrinter & friends.

I have already opened a thread under Ideas on discuss.python.org a couple days ago, but got no response (and therefore no objections *wink*).

The proposed API is:

orepr = reprlib.Repr(sort_dicts=False)
orepr(my_ordered_dict)

The default should remain True to preserve the existing behavior.

A possible implementation is here:
main...warden127:cpython:reprlib-sort_dicts

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions