Skip to content

Commit 426f99c

Browse files
authored
gh-149189: Modern defaults for pprint (#149190)
1 parent f6d16a0 commit 426f99c

14 files changed

Lines changed: 770 additions & 868 deletions

File tree

Doc/library/difflib.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -728,16 +728,18 @@ Finally, we compare the two:
728728

729729
>>> from pprint import pprint
730730
>>> pprint(result)
731-
[' 1. Beautiful is better than ugly.\n',
732-
'- 2. Explicit is better than implicit.\n',
733-
'- 3. Simple is better than complex.\n',
734-
'+ 3. Simple is better than complex.\n',
735-
'? ++\n',
736-
'- 4. Complex is better than complicated.\n',
737-
'? ^ ---- ^\n',
738-
'+ 4. Complicated is better than complex.\n',
739-
'? ++++ ^ ^\n',
740-
'+ 5. Flat is better than nested.\n']
731+
[
732+
' 1. Beautiful is better than ugly.\n',
733+
'- 2. Explicit is better than implicit.\n',
734+
'- 3. Simple is better than complex.\n',
735+
'+ 3. Simple is better than complex.\n',
736+
'? ++\n',
737+
'- 4. Complex is better than complicated.\n',
738+
'? ^ ---- ^\n',
739+
'+ 4. Complicated is better than complex.\n',
740+
'? ++++ ^ ^\n',
741+
'+ 5. Flat is better than nested.\n',
742+
]
741743

742744
As a single multi-line string it looks like this:
743745

Doc/library/pprint.rst

Lines changed: 158 additions & 240 deletions
Large diffs are not rendered by default.

Doc/library/ssl.rst

Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,67 +2473,79 @@ Visual inspection shows that the certificate does identify the desired service
24732473
(that is, the HTTPS host ``www.python.org``)::
24742474

24752475
>>> pprint.pprint(cert)
2476-
{'OCSP': ('http://ocsp.digicert.com',),
2477-
'caIssuers': ('http://cacerts.digicert.com/DigiCertSHA2ExtendedValidationServerCA.crt',),
2478-
'crlDistributionPoints': ('http://crl3.digicert.com/sha2-ev-server-g1.crl',
2479-
'http://crl4.digicert.com/sha2-ev-server-g1.crl'),
2480-
'issuer': ((('countryName', 'US'),),
2481-
(('organizationName', 'DigiCert Inc'),),
2482-
(('organizationalUnitName', 'www.digicert.com'),),
2483-
(('commonName', 'DigiCert SHA2 Extended Validation Server CA'),)),
2484-
'notAfter': 'Sep 9 12:00:00 2016 GMT',
2485-
'notBefore': 'Sep 5 00:00:00 2014 GMT',
2486-
'serialNumber': '01BB6F00122B177F36CAB49CEA8B6B26',
2487-
'subject': ((('businessCategory', 'Private Organization'),),
2488-
(('1.3.6.1.4.1.311.60.2.1.3', 'US'),),
2489-
(('1.3.6.1.4.1.311.60.2.1.2', 'Delaware'),),
2490-
(('serialNumber', '3359300'),),
2491-
(('streetAddress', '16 Allen Rd'),),
2492-
(('postalCode', '03894-4801'),),
2493-
(('countryName', 'US'),),
2494-
(('stateOrProvinceName', 'NH'),),
2495-
(('localityName', 'Wolfeboro'),),
2496-
(('organizationName', 'Python Software Foundation'),),
2497-
(('commonName', 'www.python.org'),)),
2498-
'subjectAltName': (('DNS', 'www.python.org'),
2499-
('DNS', 'python.org'),
2500-
('DNS', 'pypi.org'),
2501-
('DNS', 'docs.python.org'),
2502-
('DNS', 'testpypi.org'),
2503-
('DNS', 'bugs.python.org'),
2504-
('DNS', 'wiki.python.org'),
2505-
('DNS', 'hg.python.org'),
2506-
('DNS', 'mail.python.org'),
2507-
('DNS', 'packaging.python.org'),
2508-
('DNS', 'pythonhosted.org'),
2509-
('DNS', 'www.pythonhosted.org'),
2510-
('DNS', 'test.pythonhosted.org'),
2511-
('DNS', 'us.pycon.org'),
2512-
('DNS', 'id.python.org')),
2513-
'version': 3}
2476+
{
2477+
'OCSP': ('http://ocsp.digicert.com',),
2478+
'caIssuers': ('http://cacerts.digicert.com/DigiCertSHA2ExtendedValidationServerCA.crt',),
2479+
'crlDistributionPoints': (
2480+
'http://crl3.digicert.com/sha2-ev-server-g1.crl',
2481+
'http://crl4.digicert.com/sha2-ev-server-g1.crl',
2482+
),
2483+
'issuer': (
2484+
(('countryName', 'US'),),
2485+
(('organizationName', 'DigiCert Inc'),),
2486+
(('organizationalUnitName', 'www.digicert.com'),),
2487+
(('commonName', 'DigiCert SHA2 Extended Validation Server CA'),),
2488+
),
2489+
'notAfter': 'Sep 9 12:00:00 2016 GMT',
2490+
'notBefore': 'Sep 5 00:00:00 2014 GMT',
2491+
'serialNumber': '01BB6F00122B177F36CAB49CEA8B6B26',
2492+
'subject': (
2493+
(('businessCategory', 'Private Organization'),),
2494+
(('1.3.6.1.4.1.311.60.2.1.3', 'US'),),
2495+
(('1.3.6.1.4.1.311.60.2.1.2', 'Delaware'),),
2496+
(('serialNumber', '3359300'),),
2497+
(('streetAddress', '16 Allen Rd'),),
2498+
(('postalCode', '03894-4801'),),
2499+
(('countryName', 'US'),),
2500+
(('stateOrProvinceName', 'NH'),),
2501+
(('localityName', 'Wolfeboro'),),
2502+
(('organizationName', 'Python Software Foundation'),),
2503+
(('commonName', 'www.python.org'),),
2504+
),
2505+
'subjectAltName': (
2506+
('DNS', 'www.python.org'),
2507+
('DNS', 'python.org'),
2508+
('DNS', 'pypi.org'),
2509+
('DNS', 'docs.python.org'),
2510+
('DNS', 'testpypi.org'),
2511+
('DNS', 'bugs.python.org'),
2512+
('DNS', 'wiki.python.org'),
2513+
('DNS', 'hg.python.org'),
2514+
('DNS', 'mail.python.org'),
2515+
('DNS', 'packaging.python.org'),
2516+
('DNS', 'pythonhosted.org'),
2517+
('DNS', 'www.pythonhosted.org'),
2518+
('DNS', 'test.pythonhosted.org'),
2519+
('DNS', 'us.pycon.org'),
2520+
('DNS', 'id.python.org'),
2521+
),
2522+
'version': 3,
2523+
}
25142524

25152525
Now the SSL channel is established and the certificate verified, you can
25162526
proceed to talk with the server::
25172527

25182528
>>> conn.sendall(b"HEAD / HTTP/1.0\r\nHost: linuxfr.org\r\n\r\n")
25192529
>>> pprint.pprint(conn.recv(1024).split(b"\r\n"))
2520-
[b'HTTP/1.1 200 OK',
2521-
b'Date: Sat, 18 Oct 2014 18:27:20 GMT',
2522-
b'Server: nginx',
2523-
b'Content-Type: text/html; charset=utf-8',
2524-
b'X-Frame-Options: SAMEORIGIN',
2525-
b'Content-Length: 45679',
2526-
b'Accept-Ranges: bytes',
2527-
b'Via: 1.1 varnish',
2528-
b'Age: 2188',
2529-
b'X-Served-By: cache-lcy1134-LCY',
2530-
b'X-Cache: HIT',
2531-
b'X-Cache-Hits: 11',
2532-
b'Vary: Cookie',
2533-
b'Strict-Transport-Security: max-age=63072000; includeSubDomains',
2534-
b'Connection: close',
2535-
b'',
2536-
b'']
2530+
[
2531+
b'HTTP/1.1 200 OK',
2532+
b'Date: Sat, 18 Oct 2014 18:27:20 GMT',
2533+
b'Server: nginx',
2534+
b'Content-Type: text/html; charset=utf-8',
2535+
b'X-Frame-Options: SAMEORIGIN',
2536+
b'Content-Length: 45679',
2537+
b'Accept-Ranges: bytes',
2538+
b'Via: 1.1 varnish',
2539+
b'Age: 2188',
2540+
b'X-Served-By: cache-lcy1134-LCY',
2541+
b'X-Cache: HIT',
2542+
b'X-Cache-Hits: 11',
2543+
b'Vary: Cookie',
2544+
b'Strict-Transport-Security: max-age=63072000; includeSubDomains',
2545+
b'Connection: close',
2546+
b'',
2547+
b'',
2548+
]
25372549

25382550
See the discussion of :ref:`ssl-security` below.
25392551

Doc/library/unittest.mock.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,10 +2347,12 @@ chained call:
23472347
<MagicMock name='mock().method().other()()' id='...'>
23482348
>>> kall = call(1).method(arg='foo').other('bar')(2.0)
23492349
>>> kall.call_list()
2350-
[call(1),
2351-
call().method(arg='foo'),
2352-
call().method().other('bar'),
2353-
call().method().other()(2.0)]
2350+
[
2351+
call(1),
2352+
call().method(arg='foo'),
2353+
call().method().other('bar'),
2354+
call().method().other()(2.0),
2355+
]
23542356
>>> m.mock_calls == kall.call_list()
23552357
True
23562358

Doc/tutorial/stdlib2.rst

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,22 @@ and indentation to more clearly reveal data structure::
3030
... 'yellow'], 'blue']]]
3131
...
3232
>>> pprint.pprint(t, width=30)
33-
[[[['black', 'cyan'],
34-
'white',
35-
['green', 'red']],
36-
[['magenta', 'yellow'],
37-
'blue']]]
33+
[
34+
[
35+
[
36+
['black', 'cyan'],
37+
'white',
38+
['green', 'red'],
39+
],
40+
[
41+
[
42+
'magenta',
43+
'yellow',
44+
],
45+
'blue',
46+
],
47+
],
48+
]
3849

3950
The :mod:`textwrap` module formats paragraphs of text to fit a given screen
4051
width::

Doc/whatsnew/3.15.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,12 +1210,11 @@ pickletools
12101210
pprint
12111211
------
12121212

1213-
* Add an *expand* keyword argument for :func:`pprint.pprint`,
1214-
:func:`pprint.pformat`, :func:`pprint.pp`. If true, the output will be
1215-
formatted similar to pretty-printed :func:`json.dumps` when
1216-
*indent* is supplied.
1213+
* :mod:`pprint` now uses modern defaults: ``indent=4, width=88``,
1214+
and the default ``compact=False`` output is now formatted similar to
1215+
pretty-printed :func:`json.dumps`.
12171216
(Contributed by Stefan Todoran, Semyon Moroz and Hugo van Kemenade in
1218-
:gh:`112632`.)
1217+
:gh:`112632` and :gh:`149189`.)
12191218

12201219
* Add t-string support to :mod:`pprint`.
12211220
(Contributed by Loïc Simon and Hugo van Kemenade in :gh:`134551`.)

Lib/difflib.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -559,15 +559,17 @@ def get_grouped_opcodes(self, n=3):
559559
>>> b[23:28] = [] # Make a deletion
560560
>>> b[30] += 'y' # Make another replacement
561561
>>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes()))
562-
[[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],
563-
[('equal', 16, 19, 17, 20),
564-
('replace', 19, 20, 20, 21),
565-
('equal', 20, 22, 21, 23),
566-
('delete', 22, 27, 23, 23),
567-
('equal', 27, 30, 23, 26)],
568-
[('equal', 31, 34, 27, 30),
569-
('replace', 34, 35, 30, 31),
570-
('equal', 35, 38, 31, 34)]]
562+
[
563+
[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],
564+
[
565+
('equal', 16, 19, 17, 20),
566+
('replace', 19, 20, 20, 21),
567+
('equal', 20, 22, 21, 23),
568+
('delete', 22, 27, 23, 23),
569+
('equal', 27, 30, 23, 26),
570+
],
571+
[('equal', 31, 34, 27, 30), ('replace', 34, 35, 30, 31), ('equal', 35, 38, 31, 34)],
572+
]
571573
"""
572574

573575
codes = self.get_opcodes()
@@ -784,16 +786,18 @@ class Differ:
784786
785787
>>> from pprint import pprint as _pprint
786788
>>> _pprint(result)
787-
[' 1. Beautiful is better than ugly.\n',
788-
'- 2. Explicit is better than implicit.\n',
789-
'- 3. Simple is better than complex.\n',
790-
'+ 3. Simple is better than complex.\n',
791-
'? ++\n',
792-
'- 4. Complex is better than complicated.\n',
793-
'? ^ ---- ^\n',
794-
'+ 4. Complicated is better than complex.\n',
795-
'? ++++ ^ ^\n',
796-
'+ 5. Flat is better than nested.\n']
789+
[
790+
' 1. Beautiful is better than ugly.\n',
791+
'- 2. Explicit is better than implicit.\n',
792+
'- 3. Simple is better than complex.\n',
793+
'+ 3. Simple is better than complex.\n',
794+
'? ++\n',
795+
'- 4. Complex is better than complicated.\n',
796+
'? ^ ---- ^\n',
797+
'+ 4. Complicated is better than complex.\n',
798+
'? ++++ ^ ^\n',
799+
'+ 5. Flat is better than nested.\n',
800+
]
797801
798802
As a single multi-line string it looks like this:
799803

0 commit comments

Comments
 (0)