Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Teach pprint about frozendict #145070

Copy link
Copy link
@devdanzin

Description

@devdanzin
Issue body actions

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

easystdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
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

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.