Skip to content

Use pprint.pformat(expand=True) on Python 3.15+ for better nested reprs - #14966

Open
SakshamChawla76 wants to merge 1 commit into
pytest-dev:mainfrom
SakshamChawla76:main
Open

Use pprint.pformat(expand=True) on Python 3.15+ for better nested reprs#14966
SakshamChawla76 wants to merge 1 commit into
pytest-dev:mainfrom
SakshamChawla76:main

Conversation

@SakshamChawla76

Copy link
Copy Markdown

Description

Use pprint.pformat(expand=True) on Python 3.15+ to produce better nested reprs for complex data structures.

This addresses issue #14859 which requested using the new expand=True parameter added in Python 3.15.

Changes

  • src/_pytest/_io/saferepr.py: Added version check to use expand=True in safeformat() for Python 3.15+

Testing

  • All existing saferepr tests pass (pre-existing failures on Python 3.14 are unrelated to this change)
  • The new behavior on Python 3.15+ produces better nested reprs:
# Before (and on Python < 3.15):
{'aaaaaaaaaaaa': 1, 'bbbbbbbbbbbbbbbbbbbb': 2, 'cccccccccccccccccccccccccccccc': {'ddddd': 3, 'eeeeeeeeeeeeeeeeeeee': 3}}

# After (on Python 3.15+):
{'aaaaaaaaaaaa': 1,
 'bbbbbbbbbbbbbbbbbbbb': 2,
 'cccccccccccccccccccccccccccccc': {'ddddd': 3,
                                    'eeeeeeeeeeeeeeeeeeee': 3}}

Closes pytest-dev#14859

Signed-off-by: Saksham Chawla <sakshamchawla167@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants