Skip to content

gh-149189: Modern defaults for pprint#149190

Open
hugovk wants to merge 2 commits intopython:mainfrom
hugovk:3.15-pprint-defaults
Open

gh-149189: Modern defaults for pprint#149190
hugovk wants to merge 2 commits intopython:mainfrom
hugovk:3.15-pprint-defaults

Conversation

@hugovk
Copy link
Copy Markdown
Member

@hugovk hugovk commented Apr 30, 2026

Given:

from pprint import pprint

config = {
    "database": {
        "host": "db.example.com",
        "port": 5432,
        "options": {
            "connect_timeout": 5,
            "pool_size": 10,
            "ssl": True,
            "sslmode": "verify-full",
        },
    },
    "logging": {
        "level": "INFO",
        "file": "/var/log/app.log",
        "handlers": {
            "console": {"enabled": True},
            "file": {"rotate": True, "max_bytes": 1048576},
        },
    },
}

print("===== expand=False =====")
print()
pprint(config)

print()

print("===== expand=True =====")
print()
pprint(config, expand=True)

main produces:

{'database': {'host': 'db.example.com',
              'options': {'connect_timeout': 5,
                          'pool_size': 10,
                          'ssl': True,
                          'sslmode': 'verify-full'},
              'port': 5432},
 'logging': {'file': '/var/log/app.log',
             'handlers': {'console': {'enabled': True},
                          'file': {'max_bytes': 1048576, 'rotate': True}},
             'level': 'INFO'}}

This PR produces:

{
    'database': {
        'host': 'db.example.com',
        'options': {'connect_timeout': 5, 'pool_size': 10, 'ssl': True, 'sslmode': 'verify-full'},
        'port': 5432,
    },
    'logging': {
        'file': '/var/log/app.log',
        'handlers': {'console': {'enabled': True}, 'file': {'max_bytes': 1048576, 'rotate': True}},
        'level': 'INFO',
    },
}

@hugovk hugovk requested a review from cjw296 as a code owner April 30, 2026 16:00
@hugovk hugovk added the stdlib Standard Library Python modules in the Lib/ directory label Apr 30, 2026
@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented Apr 30, 2026

@hugovk hugovk force-pushed the 3.15-pprint-defaults branch from 89842d3 to 3f04477 Compare April 30, 2026 16:15
Copy link
Copy Markdown
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fully support this feature! I never used pprint, because I always thought that it is not actually pretty. Multilple nesting levels were really hard to read, indentation was hard to follow.

The only downside that, I think, we should empathise in the "What's new" is that this can break doctests. Let's maybe add a section on how one can restore the old behavior for all versions of Python?

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

Labels

awaiting core review stdlib Standard Library Python modules in the Lib/ directory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants