Skip to content

Teach pprint about frozendict #145070

Closed
Closed

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

  1. self-assigned this
    on Feb 21, 2026
  2. added
    type-feature
    stdlib
    on Feb 21, 2026
  3. devdanzin commented on Feb 21, 2026

    @devdanzin
    MemberAuthor

    Being addressed in #144908, which technically makes this a duplicate of #141510.

    I think it's worth keeping it open as it has a tighter scope than that issue, please close if you disagree.

  4. vstinner commented on Feb 21, 2026

    @vstinner
    Member

    Feature implementated in the change commit 770d354. I close the issue.

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

Metadata

Metadata

Assignees

Labels

easystdlibtype-feature

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions