Skip to content

Pretty-print builtin frozendict in assertion diffs - #15173

Open
HakeemTheEmperor wants to merge 1 commit into
pytest-dev:mainfrom
HakeemTheEmperor:fix-frozendict-print
Open

HakeemTheEmperor wants to merge 1 commit into
pytest-dev:mainfrom
HakeemTheEmperor:fix-frozendict-print

Conversation

@HakeemTheEmperor

Copy link
Copy Markdown

Closes #15172

On Python 3.15, assertion diffs printed frozendict on a single line because
PrettyPrinter._dispatch had no entry for it, so it fell back to a plain repr.
This registers frozendict on 3.15+, reusing _pprint_ordered_dict since both
types repr as Name({...}). Subclasses use their own class name.

The registration and test are guarded by sys.version_info >= (3, 15), with
# noqa: F821 because ruff checks against Python 3.10, where frozendict
doesn't exist.

  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits.
  • Add text like closes #XYZW to the PR description and/or commits.
  • If AI agents were used, they are credited in Co-authored-by commit trailers.
  • Create a new changelog file in the changelog directory.
  • Add yourself to AUTHORS in alphabetical order.

On Python 3.15+, register frozendict in PrettyPrinter._dispatch, reusing the OrderedDict printer since both repr as Name({...}). Previously it fell back to a single-line repr, making diffs hard to read.

Closes pytest-dev#15172
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 13, 2026

This branch has not been deployed

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

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assertion diff doesn't pretty-print the built-in frozen dict (Python 3.15)

2 participants