Repository navigation
Pretty-print builtin frozendict in assertion diffs - #15173
Conversation
bluetech
left a comment
There was a problem hiding this comment.
Thanks for looking into this.
The pprint.py file is derived from upstream's pprint code: https://github.com/python/cpython/blob/main/Lib/pprint.py
It looks like they frozendict support there is a little different from the approach taken here of reusing OrderedDict formatting.
Do you mind taking a look at the upstream change https://github.com/python/cpython/pull/144908/changes and see if it's relevant for us or not? When in doubt I'd see it's better to follow upstream (except for the specific formatting changes for which we forked from upstream in the first place).
|
Alright I'm looking into it now |
|
Thanks for the pointer. I went through the upstream change. It has two parts:
Happy to adjust if you’d rather follow upstream for part 1 as well. |
45a620a to
879c8dd
Compare
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
879c8dd to
6e6c996
Compare
bluetech
left a comment
There was a problem hiding this comment.
I made some tweaks. It's good now, thanks.
Closes #15172
On Python 3.15, assertion diffs printed
frozendicton a single line becausePrettyPrinter._dispatchhad no entry for it, so it fell back to a plain repr.This registers
frozendicton 3.15+, reusing_pprint_ordered_dictsince bothtypes repr as
Name({...}). Subclasses use their own class name.The registration and test are guarded by
sys.version_info >= (3, 15), with# noqa: F821because ruff checks against Python 3.10, wherefrozendictdoesn't exist.
closes #XYZWto the PR description and/or commits.Co-authored-bycommit trailers.changelogdirectory.AUTHORSin alphabetical order.