Repository navigation
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Description
| BPO | 18725 |
|---|---|
| Nosy | @warsaw, @birkenfeld, @pitrou, @ezio-melotti, @stevendaprano, @bitdancer, @serhiy-storchaka, @vajrasky |
| Files |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = 'https://github.com/serhiy-storchaka'
closed_at = <Date 2013-10-15.18:25:55.484>
created_at = <Date 2013-08-13.10:12:58.179>
labels = ['type-feature', 'library']
title = 'Multiline shortening'
updated_at = <Date 2013-10-16.10:09:30.760>
user = 'https://github.com/serhiy-storchaka'bugs.python.org fields:
activity = <Date 2013-10-16.10:09:30.760>
actor = 'serhiy.storchaka'
assignee = 'serhiy.storchaka'
closed = True
closed_date = <Date 2013-10-15.18:25:55.484>
closer = 'serhiy.storchaka'
components = ['Library (Lib)']
creation = <Date 2013-08-13.10:12:58.179>
creator = 'serhiy.storchaka'
dependencies = []
files = ['31736', '31971']
hgrepos = []
issue_num = 18725
keywords = ['patch', 'needs review']
message_count = 12.0
messages = ['195065', '195066', '195074', '195075', '197557', '198891', '199046', '200010', '200011', '200046', '200049', '200051']
nosy_count = 9.0
nosy_names = ['barry', 'georg.brandl', 'pitrou', 'ezio.melotti', 'steven.daprano', 'r.david.murray', 'python-dev', 'serhiy.storchaka', 'vajrasky']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue18725'
versions = ['Python 3.4']Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Activity
serhiy-storchaka commentedon Aug 13, 2013
Functions in the textwrap module works with multiline text except a newly added (in bpo-18585) the shorten() function. Wrapping and shortening a multiline text using existing textwrap function is not a trivial job.
I propose to add two new parameters to the TextWrap class and wrap() and fill() functions: max_lines and placeholder. If the max_lines argument is specified then wrapped text truncated to max_lines and the last line shortened to the width argument.
The shorten() function then will be just a particular case of fill() with max_lines=1.
pitrou commentedon Aug 13, 2013
Sounds like a reasonable enhancement to me.
vajrasky commentedon Aug 13, 2013
What about newline keyword argument?
Are we forcing the newline to be '\n'? Alternate newlines will be useful for Windows platform ('\r\n') and HTML platform ('<br />').
serhiy-storchaka commentedon Aug 13, 2013
fill(...) is just '\n'.join(wrap(...)). Directly use wrap() if you need nonstandard newlines.
serhiy-storchaka commentedon Sep 13, 2013
Here is a patch. It get rid of TextWrap.shorten() because TextWrap.fill() supersedes it and because "placeholder" now a parameter of TextWrap. Module level shorten() is left but I doubt about it.
serhiy-storchaka commentedon Oct 3, 2013
Could anyone please review the patch?
serhiy-storchaka commentedon Oct 6, 2013
In updated patch fixed a bug with final spaces.
python-dev commentedon Oct 15, 2013
New changeset 2e8c424dc638 by Serhiy Storchaka in branch 'default':
Issue bpo-18725: The textwrap module now supports truncating multiline text.
http://hg.python.org/cpython/rev/2e8c424dc638
serhiy-storchaka commentedon Oct 15, 2013
Antoine has approved this on IRC.
Thank you Ezio and Antoine for your reviews.
vajrasky commentedon Oct 16, 2013
Serhiy, you forgot to add shorten to __all__.
python-dev commentedon Oct 16, 2013
New changeset 0bd257cd3e88 by Serhiy Storchaka in branch 'default':
Add shorten to __all_ (issues bpo-18585 and bpo-18725).
http://hg.python.org/cpython/rev/0bd257cd3e88
serhiy-storchaka commentedon Oct 16, 2013
Thank you Vajrasky. It's Antoine forgot. ;)