Skip to content

Teach pprint about frozendict #145070

Description

@devdanzin

Feature or enhancement

Proposal:

The pprint code has a number of type or protocol specific handlers but doesn't have one for frozendict yet. So, we don't currently get pretty printing for frozendict:

>>> f = frozendict.fromkeys(range(10))
>>> g = frozendict.fromkeys(range(10))
>>> h = {0: f, 1: frozendict({2: g})}
>>> pprint.pp(h)
{0: frozendict({0: None, 1: None, 2: None, 3: None, 4: None, 5: None, 6: None, 7: None, 8: None, 9: None}),
 1: frozendict({2: frozendict({0: None, 1: None, 2: None, 3: None, 4: None, 5: None, 6: None, 7: None, 8: None, 9: None})})}

We want frozendict to be pretty printed like this:

>>> f = frozendict.fromkeys(range(10))
>>> g = frozendict.fromkeys(range(10))
>>> h = {0: f, 1: frozendict({2: g})}
>>> pprint.pp(h)
{0: frozendict({0: None,
                1: None,
                2: None,
                3: None,
                4: None,
                5: None,
                6: None,
                7: None,
                8: None,
                9: None}),
 1: frozendict({2: frozendict({0: None,
                               1: None,
                               2: None,
                               3: None,
                               4: None,
                               5: None,
                               6: None,
                               7: None,
                               8: None,
                               9: None})})}

Let me know whether you think the pretty printing should be different.

cc: @rhettinger for validating that the pretty printing should be as above.

I'll create a trivial PR to fix this once validated.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

easystdlibStandard 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