msg198474 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-09-27 13:40 |
The documentation says: """The pprint module provides a capability to “pretty-print” arbitrary Python data structures in a form which can be used as input to the interpreter.""" But #since long lines are splitted on shorter lines without continuation character and the result can't be used as input to the interpreter. >>> pprint.pprint('abc '*20) 'abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc '\ 'abc ' |
|
|
msg198478 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2013-09-27 14:20 |
FYI this defect was mentioned (by Antoine) in Issue17530, though that issue is about bytes. |
|
|
msg198480 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-09-27 15:11 |
Thank you David. In any case this is worth a separate issue. Here is a patch. Personally I prefer to add continuation backslash even for inner wrapped lines, but I'm not sure that most core developers will agreed with it. |
|
|
msg198488 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2013-09-27 16:11 |
According to PEP 8, parentheses should be used for multi-line expressions, not backslashes: """The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.""" Also, please note that in both cases it adds a character to the lines, which must be taken into account in the algorithm. |
|
|
msg198491 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-09-27 17:01 |
Second path uses parentheses. It is more complicated than first patch. I prefer first patch, because it is simple, because second variant wastes more width, because parentheses looks too similar to tuple, and because "implicit string literal concatenation considered harmful"[1]. http://comments.gmane.org/gmane.comp.python.ideas/20525 |
|
|
msg198492 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2013-09-27 17:17 |
> "implicit string literal concatenation considered harmful" Both patches rely on implicit string literal concatenation. Another possibility is not fixing this issue, and deciding it is normal behaviour. It is trivial to add parentheses if you need them. |
|
|
msg198494 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-09-27 18:12 |
> Both patches rely on implicit string literal concatenation. But with backslash it *looks* less implicit. > Another possibility is not fixing this issue, and deciding it is normal behaviour. It is trivial to add parentheses if you need them. It would be safer just do not wrap long line on first level. |
|
|
msg198502 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2013-09-27 20:53 |
> > Another possibility is not fixing this issue, and deciding it is > normal behaviour. It is trivial to add parentheses if you need them. > > It would be safer just do not wrap long line on first level. That would defeat the whole point of pprint(). |
|
|
msg198666 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-09-29 22:48 |
The whole point of pprint() is formatted output of containers such as list or dict. Before 3.4 it does not wrap long strings at all. Of course I don't think this alternative is good. But at least it is better than producing illegal output. |
|
|
msg198667 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2013-09-29 22:51 |
> The whole point of pprint() is formatted output of containers such as > list or dict. Well, the whole point of pprint is pretty-printing. Being restricted to containers is a bug, not a feature... |
|
|
msg198668 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-09-29 22:54 |
I doubt we are able to fix it in maintained releases. |
|
|
msg206271 - (view) |
Author: Mark Lawrence (BreamoreBoy) * |
Date: 2013-12-16 01:29 |
Would it pay to have a meta issue for all the outstanding pprint issues, or possibly make issue 7434 the meta issue? |
|
|
msg232416 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2014-12-10 08:59 |
What to do with this issue? |
|
|
msg232978 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2014-12-20 19:02 |
New changeset 872f048f0403 by Serhiy Storchaka in branch '3.4': Issue #19104: pprint now produces evaluable output for wrapped strings. https://hg.python.org/cpython/rev/872f048f0403 New changeset 4d3066d4a5df by Serhiy Storchaka in branch 'default': Issue #19104: pprint now produces evaluable output for wrapped strings. https://hg.python.org/cpython/rev/4d3066d4a5df |
|
|
msg232981 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2014-12-20 19:44 |
Thank you Antoine for your review. |
|
|