Skip to content

TextWrap vs words 1-character shorter than the width #45487

Closed

Description

@sam
mannequin
BPO 1146
Nosy @birkenfeld
Files
  • textwrap_r58153.diff
  • textwrap_revised_r58153.diff
  • textwrap_revised_r60075.diff
  • 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 = 'https://github.com/birkenfeld'
    closed_at = <Date 2008-01-19.19:48:42.054>
    created_at = <Date 2007-09-11.13:37:37.004>
    labels = ['type-bug']
    title = 'TextWrap vs words 1-character shorter than the width'
    updated_at = <Date 2008-01-19.19:48:42.053>
    user = 'https://bugs.python.org/sam'

    bugs.python.org fields:

    activity = <Date 2008-01-19.19:48:42.053>
    actor = 'georg.brandl'
    assignee = 'georg.brandl'
    closed = True
    closed_date = <Date 2008-01-19.19:48:42.054>
    closer = 'georg.brandl'
    components = []
    creation = <Date 2007-09-11.13:37:37.004>
    creator = 'sam'
    dependencies = []
    files = ['8428', '8429', '9216']
    hgrepos = []
    issue_num = 1146
    keywords = ['patch']
    message_count = 6.0
    messages = ['55822', '55909', '55910', '55911', '60171', '60221']
    nosy_count = 3.0
    nosy_names = ['georg.brandl', 'sam', 'quentin.gallet-gilles']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1146'
    versions = ['Python 2.5']

    Activity

    1. sam commented on Sep 11, 2007

      sammannequin
      MannequinAuthor
      >>> from textwrap import wrap
      >>> wrap("foobarbaz reallylongwordgoeshere", width = 10)
      ['foobarbaz r', 'eallylongw', 'ordgoesher', 'e']
      >>> print [len(s) for s in _]
      [11, 10, 10, 1]

      This only seems to happen when the first word on the line is exactly one
      character shorter than the width, and the next word is too long to fit,
      so it is broken:

      >>> wrap("foo bar reallylongwordgoeshere", width = 7)
      ['foo bar', 'reallyl', 'ongword', 'goesher', 'e']
      >>> wrap("foobarbaz really longwordgoeshere", width = 10)
      ['foobarbaz', 'really lon', 'gwordgoesh', 'ere']
      >>> wrap("foobarbaz reallylongwordgoeshere", width = 10,
      break_long_words = False)
      ['foobarbaz', 'reallylongwordgoeshere']

      This is on Python 2.5, on Windows XP SP2.

    2. added
      type-bugAn unexpected behavior, bug, or error
      on Sep 11, 2007
    3. quentingallet-gilles commented on Sep 14, 2007

      quentingallet-gillesmannequin
      Mannequin

      The bug is present in trunk and has been there since rev 33955. This
      revision contained a fix to an infinite loop when indentation was set
      longer than width with long word breaking enabled. In that case, it
      would strip off at least one character on every pass. The fix was
      however a bit too general, leading to the reported bug.

      The added patch makes sure this doesn't happen anymore when indentation
      isn't involved.

    4. quentingallet-gilles commented on Sep 14, 2007

      quentingallet-gillesmannequin
      Mannequin

      The previous patch is suboptimal and doesn't solve all cases. This one
      does. My apologies.

    5. birkenfeld commented on Sep 14, 2007

      @birkenfeld
      Member

      I'll look at this shortly.

    6. self-assigned this
      on Sep 14, 2007
    7. quentingallet-gilles commented on Jan 19, 2008

      quentingallet-gillesmannequin
      Mannequin

      As i revisited this one for the Bug Day, I found I could optimize the
      patch a little bit. Here's the updated diff.

      Also... I think it's a good candidate for 2.5 maintenance release. Any
      thoughts ?

    8. birkenfeld commented on Jan 19, 2008

      @birkenfeld
      Member

      Thanks for the patches, committed in r60093!

    9. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions