Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pprint could use line continuation for long string literals #61352

Closed
pitrou opened this issue Feb 7, 2013 · 8 comments
Closed

pprint could use line continuation for long string literals #61352

pitrou opened this issue Feb 7, 2013 · 8 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@pitrou
Copy link
Member

pitrou commented Feb 7, 2013

BPO 17150
Nosy @freddrake, @rhettinger, @pitrou
Files
  • str_pprint.patch
  • str_pprint2.patch
  • 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 = None
    closed_at = <Date 2013-03-23.19:37:04.171>
    created_at = <Date 2013-02-07.12:51:07.541>
    labels = ['type-feature', 'library']
    title = 'pprint could use line continuation for long string literals'
    updated_at = <Date 2013-03-24.15:55:00.642>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2013-03-24.15:55:00.642>
    actor = 'rhettinger'
    assignee = 'none'
    closed = True
    closed_date = <Date 2013-03-23.19:37:04.171>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2013-02-07.12:51:07.541>
    creator = 'pitrou'
    dependencies = []
    files = ['29492', '29515']
    hgrepos = []
    issue_num = 17150
    keywords = ['patch']
    message_count = 8.0
    messages = ['181599', '181605', '181643', '184695', '184808', '185076', '185077', '185141']
    nosy_count = 4.0
    nosy_names = ['fdrake', 'rhettinger', 'pitrou', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue17150'
    versions = ['Python 3.4']

    @pitrou
    Copy link
    Member Author

    pitrou commented Feb 7, 2013

    Currently:

    >>> pprint.pprint({"a": "xxx " * 50})
    {'a': 'xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx '}

    It would be nicer if it produced something like:

    >>> pprint.pprint({"a": "xxx " * 50})
    {'a': 'xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx '
          'xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx '
          'xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx '
          'xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx '
          'xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx '}

    (for the record, the real-world use case I encountered was when printing some pyudev data)

    @pitrou pitrou added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Feb 7, 2013
    @freddrake
    Copy link
    Member

    I like this.

    It would be especially nice if it were smart enough to split the segments after sequences of line-ends (r'(\r?\n)+').

    @pitrou
    Copy link
    Member Author

    pitrou commented Feb 7, 2013

    I was thinking we could re-use textwrap, actually.

    @pitrou
    Copy link
    Member Author

    pitrou commented Mar 19, 2013

    Here is a patch.

    @pitrou
    Copy link
    Member Author

    pitrou commented Mar 20, 2013

    Here is a new patch with more tests and updated docs.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 23, 2013

    New changeset 5a2296093645 by Antoine Pitrou in branch 'default':
    Issue bpo-17150: pprint now uses line continuations to wrap long string literals.
    http://hg.python.org/cpython/rev/5a2296093645

    @pitrou
    Copy link
    Member Author

    pitrou commented Mar 23, 2013

    Ok, I've committed the patch.

    @pitrou pitrou closed this as completed Mar 23, 2013
    @rhettinger
    Copy link
    Contributor

    This is a nice addition. Thank you.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants