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.

Author mdear
Recipients mdear
Date 2015-02-22.00:57:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1424566675.14.0.0615952821634.issue23497@psf.upfronthosting.co.za>
In-reply-to
Content
The textwrap.dedent function does not work when the string to dedent itself contains embedded strings that contain newline characters.

https://docs.python.org/3.4/library/textwrap.html?highlight=dedent#textwrap.dedent states that this function "can be used to make triple-quoted strings line up with the left edge of the display".

It just so happens that my triple-quoted string itself contains a single-quoted string with newline characters.  I would have expected textwrap.dedent to ignore these newline characters inside single or double quoted strings contained in the larger triple-quoted string.


The semantics of this bug may be slightly different than https://bugs.python.org/issue19479 "textwrap.dedent doesn't work properly with strings containing CRLF", so I'm raising a new issue.

I am seeing this in a module I'm writing that emits synthetic python code that is subsequently passed back into the interpreter via "exec".

Python 3.4.1 (default, Nov 12 2014, 13:34:29) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from textwrap import dedent
>>> s = '''
...     'my_key' : r'my value which contains \n character'
... '''
>>> s
"\n    'my_key' : r'my value which contains \n character'\n"
>>> dedent(s)
"\n   'my_key' : r'my value which contains \ncharacter'\n"
>>>
History
Date User Action Args
2015-02-22 00:57:55mdearsetrecipients: + mdear
2015-02-22 00:57:55mdearsetmessageid: <1424566675.14.0.0615952821634.issue23497@psf.upfronthosting.co.za>
2015-02-22 00:57:55mdearlinkissue23497 messages
2015-02-22 00:57:54mdearcreate