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.
Created on 2013年09月27日 13:40 by serhiy.storchaka, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| pprint_str_evaluable.patch | serhiy.storchaka, 2013年09月27日 15:11 | Use backslashes | review | |
| pprint_str_evaluable_2.patch | serhiy.storchaka, 2013年09月27日 17:01 | Use parentheses | review | |
| Messages (15) | |||
|---|---|---|---|
| msg198474 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | 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 issue17150 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) * (Python committer) | 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) * (Python committer) | 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) * (Python committer) | 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) * (Python committer) | 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) * (Python committer) | 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) * (Python committer) | 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) * (Python committer) | 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) * (Python committer) | 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) * (Python committer) | 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) * (Python committer) | 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) * (Python committer) | Date: 2014年12月10日 08:59 | |
What to do with this issue? |
|||
| msg232978 - (view) | Author: Roundup Robot (python-dev) (Python triager) | 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) * (Python committer) | Date: 2014年12月20日 19:44 | |
Thank you Antoine for your review. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:51 | admin | set | github: 63303 |
| 2014年12月20日 19:44:15 | serhiy.storchaka | set | status: open -> closed messages: + msg232981 assignee: serhiy.storchaka resolution: fixed stage: patch review -> resolved |
| 2014年12月20日 19:02:26 | python-dev | set | nosy:
+ python-dev messages: + msg232978 |
| 2014年12月20日 18:50:23 | serhiy.storchaka | link | issue17530 dependencies |
| 2014年12月19日 00:11:02 | Arfrever | set | nosy:
+ Arfrever |
| 2014年12月18日 15:37:44 | serhiy.storchaka | set | keywords: + needs review |
| 2014年12月10日 08:59:00 | serhiy.storchaka | set | messages:
+ msg232416 versions: + Python 3.5 |
| 2014年02月03日 15:42:39 | BreamoreBoy | set | nosy:
- BreamoreBoy |
| 2013年12月16日 01:29:41 | BreamoreBoy | set | nosy:
+ BreamoreBoy messages: + msg206271 |
| 2013年09月29日 22:54:51 | serhiy.storchaka | set | messages: + msg198668 |
| 2013年09月29日 22:51:40 | pitrou | set | messages: + msg198667 |
| 2013年09月29日 22:48:04 | serhiy.storchaka | set | messages: + msg198666 |
| 2013年09月27日 20:53:08 | pitrou | set | messages: + msg198502 |
| 2013年09月27日 18:12:23 | serhiy.storchaka | set | messages: + msg198494 |
| 2013年09月27日 17:17:46 | pitrou | set | messages: + msg198492 |
| 2013年09月27日 17:01:55 | serhiy.storchaka | set | files:
+ pprint_str_evaluable_2.patch messages: + msg198491 |
| 2013年09月27日 16:11:46 | pitrou | set | messages: + msg198488 |
| 2013年09月27日 15:12:04 | serhiy.storchaka | link | issue19103 dependencies |
| 2013年09月27日 15:11:11 | serhiy.storchaka | set | files:
+ pprint_str_evaluable.patch keywords: + patch messages: + msg198480 stage: needs patch -> patch review |
| 2013年09月27日 14:20:22 | r.david.murray | set | nosy:
+ r.david.murray messages: + msg198478 |
| 2013年09月27日 13:40:50 | serhiy.storchaka | create | |