René's URL Explorer Experiment


Title: Modern defaults for `pprint` · Issue #149189 · python/cpython · GitHub

Open Graph Title: Modern defaults for `pprint` · Issue #149189 · python/cpython

X Title: Modern defaults for `pprint` · Issue #149189 · python/cpython

Description: Feature or enhancement Proposal: Python 3.15 introduces the expand keyword for pprint, which improves the output: expand (bool) – If True, opening parentheses and brackets will be followed by a newline and the following content will be i...

Open Graph Description: Feature or enhancement Proposal: Python 3.15 introduces the expand keyword for pprint, which improves the output: expand (bool) – If True, opening parentheses and brackets will be followed by a new...

X Description: Feature or enhancement Proposal: Python 3.15 introduces the expand keyword for pprint, which improves the output: expand (bool) – If True, opening parentheses and brackets will be followed by a new...

Opengraph URL: https://github.com/python/cpython/issues/149189

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Modern defaults for `pprint`","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nPython 3.15 introduces the `expand` keyword for [`pprint`](https://docs.python.org/3.15/library/pprint.html), which improves the output:\n\n\u003e * **expand** (_bool_) – If `True`, opening parentheses and brackets will be followed by\n\u003e   a newline and the following content will be indented by one level, similar to\n\u003e   pretty-printed JSON. Incompatible with _compact_.\n\nFor example, this code:\n\n```python\nfrom pprint import pprint\n\nconfig = {\n    \"database\": {\n        \"host\": \"db.example.com\",\n        \"port\": 5432,\n        \"options\": {\n            \"connect_timeout\": 5,\n            \"pool_size\": 10,\n            \"ssl\": True,\n            \"sslmode\": \"verify-full\",\n        },\n    },\n    \"logging\": {\n        \"level\": \"INFO\",\n        \"file\": \"/var/log/app.log\",\n        \"handlers\": {\n            \"console\": {\"enabled\": True},\n            \"file\": {\"rotate\": True, \"max_bytes\": 1048576},\n        },\n    },\n}\n\nprint(\"===== expand=False =====\")\nprint()\npprint(config)\n\nprint()\n\nprint(\"===== expand=True =====\")\nprint()\npprint(config, expand=True)\n```\n\nProduces:\n\n```\n===== expand=False =====\n\n{'database': {'host': 'db.example.com',\n              'options': {'connect_timeout': 5,\n                          'pool_size': 10,\n                          'ssl': True,\n                          'sslmode': 'verify-full'},\n              'port': 5432},\n 'logging': {'file': '/var/log/app.log',\n             'handlers': {'console': {'enabled': True},\n                          'file': {'max_bytes': 1048576, 'rotate': True}},\n             'level': 'INFO'}}\n\n===== expand=True =====\n\n{\n 'database': {\n  'host': 'db.example.com',\n  'options': {\n   'connect_timeout': 5,\n   'pool_size': 10,\n   'ssl': True,\n   'sslmode': 'verify-full',\n  },\n  'port': 5432,\n },\n 'logging': {\n  'file': '/var/log/app.log',\n  'handlers': {\n   'console': {'enabled': True},\n   'file': {'max_bytes': 1048576, 'rotate': True},\n  },\n  'level': 'INFO',\n },\n}\n```\n\n\"Prettiness\" is subjective, but in my opinion, the expanded output looks nicer and is much easier to read. It's also closer to code formatted with modern tools like Black and Ruff.\n\n## Opinions about `pprint`\n\nOthers also don't like the current default:\n\n\u003e For a long time I was unhappy with default values that standard pprint module has\n\u003e (`from pprint import pprint`). So, I decided to change them as I like and not pass\n\u003e them every call to pprint.\n\nhttps://alex-ber.medium.com/my-pprint-module-f25a7b695e5f\n\n\u003e However, it has a very greedy layout algorithm that fails to produce pretty output in\n\u003e many cases.\n\nhttps://tommikaikkonen.github.io/introducing-prettyprinter-for-python/\n\n\u003e `pprint++`: a drop-in replacement for `pprint` that's actually pretty ... Why is it\n\u003e prettier? Unlike `pprint`, `pprint++ strives to emit a readable, largely\n\u003e PEP8-compliant, representation of its input.\n\nhttps://github.com/wolever/pprintpp\n\n\u003e the current output for a large nested dictionary with pprint is basically unusable and\n\u003e definitely not pretty, which is a shame because large dictionaries are probably the\n\u003e primary use case for pprint.\n\nhttps://github.com/python/cpython/issues/112632#issuecomment-2597056481\n\n\u003e When working with deeply nested dictionaries (depth 4+), readability becomes critical.\n\u003e Python’s built-in `pprint module is the default choice for \"pretty printing,\" but it\n\u003e often falls short with deep nesting—producing cluttered, inconsistently indented\n\u003e output that’s hard to parse.\n\nhttps://www.pythontutorials.net/blog/how-to-pretty-print-nested-dictionaries/\n\n\u003e I don't really fancy the way Python's pprint formats the output. [...] But I'd like it\n\u003e to be [...] in the style of Black\n\nhttps://stackoverflow.com/questions/69945869/pretty-printing-python-dictionary-lists-in-black-style\n\n## Other tools and workarounds\n\nThe formatting can be improved by using third-party libraries, for example, `rich.print()`, and `pprintpp` and `alexber.utils.pprint` mentioned above. Or by changing the defaults yourself, or following an oft-recommended and somewhat roundabout `print(json.dumps(d, indent=4))`.\n\nBut `pprint` is often used for debugging because it's always within arm's reach: you just want to `import pprint as pprint` and `pprint(my_var)`.\n\nTherefore, I believe it would be beneficial to modernise `pprint`'s defaults:\n\n| argument | before  | after  |\n| -------- | ------- | ------ |\n| `expand` | `False` | `True` |\n| `indent` | `1`     | `4`    |\n| `width`  | `80`    | `88`   |\n\n## `pp()`\n\n[`pp()`](https://docs.python.org/3/library/pprint.html#pprint.pp) was [added to 3.8 in 2017](https://github.com/python/cpython/issues/74855). It's the same as `pprint()` but with `sort_dicts=False`.\n\nThis is from the discussion preceding its addition, which considered changing the `pprint()` default:\n\n\u003e \u003e I guess the underlying issue here is partly the question of what the pprint module\n\u003e \u003e is for. In my understanding, it's primarily a tool for debugging/introspecting\n\u003e \u003e Python programs, and the reason it talks about \"valid input to the interpreter\"\n\u003e \u003e isn't because we want anyone to actually feed the data back into the interpreter,\n\u003e \u003e but to emphasize that it provides an accurate what-you-see-is-what's-really-there\n\u003e \u003e view into how the interpreter understands a given object. It also emphasizes that\n\u003e \u003e this is not intended for display to end users; making the output format be \"Python\n\u003e \u003e code\" suggests that the main intended audience is people who know how to read, well,\n\u003e \u003e Python code, and therefore can be expected to care about Python's semantics.\n\u003e\n\u003e pprint.pprint() is indeed mostly for debugging, but not always. As an example of what\n\u003e will break if you change the sorting guarantee: in Mailman 3 the REST etag is\n\u003e calculated from the pprint.pformat() of the result dictionary before it’s JSON-ified.\n\u003e If the order is changed, then it’s possible a client will have an incorrect etag for a\n\u003e structure that is effectively the same.\n\nhttps://mail.python.org/archives/list/python-dev@python.org/message/UYMINUYHZ3O7B2DKXI7B2T42TYCJFZ3N/\nhttps://mail.python.org/pipermail/python-dev/2017-December/151403.html\n\nI agree changing `sort_dicts` changes the _code_ output.\n\nBut _display_ output is different and is safer to change: parsing the output will get you the same thing. As long as you're not doing brittle character-level parsing, it's essentially the same Python code.\n\n\n## Alternatives\n\nI'm also open to:\n\n- Only change defaults for `pp` (similar to [this suggestion](https://discuss.python.org/t/the-pprint-module-should-use-the-terminal-width-where-available/27658/3))\n- Add a new function with these defaults, somewhat similar to `pp`\n- Perhaps a new keyword to define a new style, that would override these defaults\n\n\n### Has this already been discussed elsewhere?\n\nNo response given\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-149190\n* gh-150249\n* gh-150268\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/hugovk","@type":"Person","name":"hugovk"},"datePublished":"2026-04-30T15:55:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/149189/cpython/issues/149189"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:ff6db97f-69a8-b34b-2974-114cb615147d
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idEBF0:1ECA58:A9F5C5:E23D9D:6A52B8DC
html-safe-noncee4898ba0ed8d4ae9e6aed221de27a80415aa83bf3b2256873ad6c2bd0cdd41e8
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQkYwOjFFQ0E1ODpBOUY1QzU6RTIzRDlEOjZBNTJCOERDIiwidmlzaXRvcl9pZCI6IjUyMDcwMzcyNDg3Mzc1ODk0MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac9ffb4143211514afdb09cfb6c26c083c50fbab2d19b6e292ae2f592073b8de26
hovercard-subject-tagissue:4359473853
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/149189/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ea54f72ed15a81996eef40d055fe8be4848c4918028cc00fa67cdee06b76bbc3/python/cpython/issues/149189
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ea54f72ed15a81996eef40d055fe8be4848c4918028cc00fa67cdee06b76bbc3/python/cpython/issues/149189
og:image:altFeature or enhancement Proposal: Python 3.15 introduces the expand keyword for pprint, which improves the output: expand (bool) – If True, opening parentheses and brackets will be followed by a new...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamehugovk
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release07a982c1d40157c619b364352b704c3ce66bb332
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/149189#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F149189
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F149189
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/149189
Reloadhttps://github.com/python/cpython/issues/149189
Reloadhttps://github.com/python/cpython/issues/149189
Please reload this pagehttps://github.com/python/cpython/issues/149189
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/149189
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.8k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Modern defaults for pprinthttps://github.com/python/cpython/issues/149189#top
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/hugovk
hugovkhttps://github.com/hugovk
on Apr 30, 2026https://github.com/python/cpython/issues/149189#issue-4359473853
pprinthttps://docs.python.org/3.15/library/pprint.html
https://alex-ber.medium.com/my-pprint-module-f25a7b695e5fhttps://alex-ber.medium.com/my-pprint-module-f25a7b695e5f
https://tommikaikkonen.github.io/introducing-prettyprinter-for-python/https://tommikaikkonen.github.io/introducing-prettyprinter-for-python/
https://github.com/wolever/pprintpphttps://github.com/wolever/pprintpp
#112632 (comment)https://github.com/python/cpython/issues/112632#issuecomment-2597056481
https://www.pythontutorials.net/blog/how-to-pretty-print-nested-dictionaries/https://www.pythontutorials.net/blog/how-to-pretty-print-nested-dictionaries/
https://stackoverflow.com/questions/69945869/pretty-printing-python-dictionary-lists-in-black-stylehttps://stackoverflow.com/questions/69945869/pretty-printing-python-dictionary-lists-in-black-style
pp()https://docs.python.org/3/library/pprint.html#pprint.pp
added to 3.8 in 2017https://github.com/python/cpython/issues/74855
https://mail.python.org/archives/list/python-dev@python.org/message/UYMINUYHZ3O7B2DKXI7B2T42TYCJFZ3N/https://mail.python.org/archives/list/python-dev@python.org/message/UYMINUYHZ3O7B2DKXI7B2T42TYCJFZ3N/
https://mail.python.org/pipermail/python-dev/2017-December/151403.htmlhttps://mail.python.org/pipermail/python-dev/2017-December/151403.html
this suggestionhttps://discuss.python.org/t/the-pprint-module-should-use-the-terminal-width-where-available/27658/3
gh-149189: Modern defaults for pprint #149190https://github.com/python/cpython/pull/149190
gh-149189: Revert "Modern defaults for pprint (#149190)" #150249https://github.com/python/cpython/pull/150249
[3.15] gh-149189: Revert "Modern defaults for pprint (GH-149190)" (GH-150249) #150268https://github.com/python/cpython/pull/150268
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
Release and Deferred blockers 🚫https://github.com/orgs/python/projects/2
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.