Repository navigation
fix(pprint): pretty-print frozendict (Python 3.15+) key-per-line in assertion diffs - #15260
Closed
Abhiroop3917 wants to merge 2 commits into
Closed
Abhiroop3917 wants to merge 2 commits into
Abhiroop3917 wants to merge 2 commits into
Conversation
…iffs
Python 3.15 adds frozendict as a built-in (PEP 814). Because pprint.py had
no dispatch handler for it, frozendict values fell back to a single-line
repr(), hiding the changed key mid-line in assertion diffs.
Add _pprint_frozendict, registered only when builtins.frozendict exists, so
Python < 3.15 is unaffected. The handler mirrors _pprint_ordered_dict:
wraps the dict formatting in frozendict({...}) so each key prints on its
own line, matching the dict behaviour users already rely on.
Closes pytest-dev#15172
for more information, see https://pre-commit.ci
Member
|
Thanks, but there is already a PR open for this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of changes
AI?
Checklist
Description
Python 3.15 added
frozendictas a built-in type (PEP 814). When an assertion comparing two lists of frozendicts fails with-vv, the "Full diff" prints each frozendict on a single line because_pytest/_io/pprint.pyhas no dispatch handler for it, falling through torepr().A
dictwith the same contents gets one key per line, making the changed value easy to spot. Withfrozendictthe change is buried mid-line.Root cause:
PrettyPrinter._dispatchhas handlers fordict,OrderedDict,defaultdict,MappingProxyType, etc., but notfrozendict.Fix: Add
_pprint_frozendict, mirroring_pprint_ordered_dict, and register it only whenbuiltins.frozendictexists (Python 3.15+). Older Python versions are completely unaffected.Before:
After:
closes #15172