Skip to content

Commit c593056

Browse files
committed
Fix the default placeholder in textwrap.shorten() to be " [...]".
For some reason I forgot to do it before committing the patch in issue #18585.
1 parent 05eafa8 commit c593056

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

‎Doc/library/textwrap.rst‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ functions should be good enough; otherwise, you should use an instance of
4040
:func:`wrap`.
4141

4242

43-
.. function:: shorten(text, width=70, *, placeholder=" (...)")
43+
.. function:: shorten(text, width=70, *, placeholder=" [...]")
4444

4545
Collapse and truncate the given text to fit in the given width.
4646

@@ -51,7 +51,7 @@ functions should be good enough; otherwise, you should use an instance of
5151
>>> textwrap.shorten("Hello world!", width=12)
5252
'Hello world!'
5353
>>> textwrap.shorten("Hello world!", width=11)
54-
'Hello (...)'
54+
'Hello [...]'
5555
>>> textwrap.shorten("Hello world", width=10, placeholder="...")
5656
'Hello...'
5757

@@ -268,7 +268,7 @@ hyphenated words; only then will long words be broken if necessary, unless
268268
containing the wrapped paragraph.
269269

270270

271-
.. function:: shorten(text, *, placeholder=" (...)")
271+
.. function:: shorten(text, *, placeholder=" [...]")
272272

273273
Collapse and truncate the given text to fit in :attr:`width`
274274
characters.

‎Lib/test/test_textwrap.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -786,11 +786,11 @@ def test_simple(self):
786786
# Simple case: just words, spaces, and a bit of punctuation
787787
text = "Hello there, how are you this fine day? I'm glad to hear it!"
788788

789-
self.check_shorten(text, 18, "Hello there, (...)")
789+
self.check_shorten(text, 18, "Hello there, [...]")
790790
self.check_shorten(text, len(text), text)
791791
self.check_shorten(text, len(text) - 1,
792792
"Hello there, how are you this fine day? "
793-
"I'm glad to (...)")
793+
"I'm glad to [...]")
794794

795795
def test_placeholder(self):
796796
text = "Hello there, how are you this fine day? I'm glad to hear it!"
@@ -816,13 +816,13 @@ def test_whitespace(self):
816816
"breaks and tabs too.")
817817
self.check_shorten(text, 61,
818818
"This is a paragraph that already has line "
819-
"breaks and (...)")
819+
"breaks and [...]")
820820

821821
self.check_shorten("hello world! ", 12, "hello world!")
822-
self.check_shorten("hello world! ", 11, "hello (...)")
822+
self.check_shorten("hello world! ", 11, "hello [...]")
823823
# The leading space is trimmed from the placeholder
824824
# (it would be ugly otherwise).
825-
self.check_shorten("hello world! ", 10, "(...)")
825+
self.check_shorten("hello world! ", 10, "[...]")
826826

827827
def test_width_too_small_for_placeholder(self):
828828
wrapper = TextWrapper(width=8)
@@ -831,7 +831,7 @@ def test_width_too_small_for_placeholder(self):
831831
wrapper.shorten("x" * 20, placeholder="(.......)")
832832

833833
def test_first_word_too_long_but_placeholder_fits(self):
834-
self.check_shorten("Helloo", 5, "(...)")
834+
self.check_shorten("Helloo", 5, "[...]")
835835

836836

837837
if __name__ == '__main__':

‎Lib/textwrap.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# since 0xa0 is not in range(128).
2020
_whitespace = '\t\n\x0b\x0c\r '
2121

22-
_default_placeholder = ' (...)'
22+
_default_placeholder = ' [...]'
2323

2424
class TextWrapper:
2525
"""
@@ -376,7 +376,7 @@ def shorten(text, width, *, placeholder=_default_placeholder, **kwargs):
376376
>>> textwrap.shorten("Hello world!", width=12)
377377
'Hello world!'
378378
>>> textwrap.shorten("Hello world!", width=11)
379-
'Hello (...)'
379+
'Hello [...]'
380380
"""
381381
w = TextWrapper(width=width, **kwargs)
382382
return w.shorten(text, placeholder=placeholder)

0 commit comments

Comments
 (0)