This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add textwrap.dedent, .indent, as str methods.
Type: enhancement Stage: patch review
Components: Versions: Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Julian, SpaghettiToastBook, barry, cvrebert, eric.araujo, eric.snow, ezio.melotti, martin.panter, ncoghlan, serhiy.storchaka, terry.reedy, tshepang
Priority: normal Keywords:

Created on 2013-07-01 05:33 by terry.reedy, last changed 2022-04-11 14:57 by admin.

Messages (7)
msg192109 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-07-01 05:33
To end proposals for new syntax to do what they do for triple-quoted strings. Nick Coghlan gave reasons as follows: run time cost small, can be optimized away, would be used more than some other string methods. 
http://mail.python.org/pipermail/python-ideas/2013-July/021717.html

In response, Guido said "That's a compelling argument. Let's do it."
http://mail.python.org/pipermail/python-ideas/2013-July/021718.html
msg192114 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-07-01 08:35
It turns out there's one slight wrinkle in this grand plan: it won't work for docstrings without some additional tweaking to allow for method calls in the docstring detection.

>>> def f():
...     """example""".lower()
... 
>>> print(f.__doc__)
None
>>> import dis
>>> dis.dis(f)
  2           0 LOAD_CONST               1 ('example') 
              3 LOAD_ATTR                0 (lower) 
              6 CALL_FUNCTION            0 (0 positional, 0 keyword pair) 
              9 POP_TOP              
             10 LOAD_CONST               0 (None) 
             13 RETURN_VALUE
msg192115 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-07-01 08:36
I still think the methods are worth adding regardless - I just anticipate a request to allow method calls on docstrings to follow not long after ;)
msg192116 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-07-01 09:35
str already have too many methods. Who uses str.swapcase() or str.zfill() now? I'm -0.5 for adding any new str methods.
msg192133 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2013-07-01 15:24
.dedent() is a no-brainer.  JFDI.  +1

.indent() I guess makes sense for symmetry, although I've rarely used it.  -0

As for docstrings, I can imagine other alternatives, so let's let someone interested in that go through the PEP process.
msg192148 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2013-07-01 20:13
IMO it’s fine that docstrings continue to live as pure string literals, and documentation tools continue to follow PEP 257’s advice.
msg196696 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2013-09-01 01:58
If this goes ahead, would a bytes.dedent() method be also considered? I recently discovered that textwrap.dedent() does not work on bytes() in Python 3. I would have used it for the contents of an input file in a test case.

For the record there’s an older issue 1237680 on this, rejected in 2005.
History
Date User Action Args
2022-04-11 14:57:47adminsetgithub: 62535
2013-09-01 01:58:54martin.pantersetnosy: + martin.panter
messages: + msg196696
2013-08-15 12:40:24pitrousetstage: test needed -> patch review
2013-08-15 12:03:20Juliansetnosy: + Julian
2013-08-08 16:59:09ezio.melottisetnosy: + ezio.melotti
2013-07-05 16:27:31tshepangsetnosy: + tshepang
2013-07-01 22:23:49eric.snowsetnosy: + eric.snow
2013-07-01 20:13:57eric.araujosetnosy: + eric.araujo
messages: + msg192148
2013-07-01 15:24:21barrysetmessages: + msg192133
2013-07-01 15:20:36barrysetnosy: + barry
2013-07-01 09:35:33serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg192116
2013-07-01 08:36:43ncoghlansetmessages: + msg192115
2013-07-01 08:35:11ncoghlansetmessages: + msg192114
2013-07-01 06:08:49cvrebertsetnosy: + cvrebert
2013-07-01 05:52:57SpaghettiToastBooksetnosy: + SpaghettiToastBook
2013-07-01 05:33:49terry.reedycreate