[ python-Bugs-847346 ] textwrap ignoring fix_sentence_endings for single lines

SourceForge.net noreply at sourceforge.net
Mon Nov 24 14:53:24 EST 2003


Bugs item #847346, was opened at 2003-11-22 14:12
Message generated for change (Comment added) made by nnorwitz
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=847346&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Tom Lynn (tlynn)
>Assigned to: Greg Ward (gward)
Summary: textwrap ignoring fix_sentence_endings for single lines

Initial Comment:
>>> import textwrap
>>> t=textwrap.
TextWrapper(fix_sentence_endings=True)
>>> print t.fill("A short line. Note the single space.")
A short line. Note the single space.

TextWrapper.wrap() is implemented as:

    def wrap(self, text):
        text = self._munge_whitespace(text)
        indent = self.initial_indent
        # *** Next line seems to be the bug ***
        if len(text) + len(indent) <= self.width:
            return [indent + text]
        chunks = self._split(text)
        if self.fix_sentence_endings:
            self._fix_sentence_endings(chunks)
        return self._wrap_chunks(chunks)

(if sf breaks the indentation, check the actual source!)

That early-return "if" clause seems to be an incorrect 
optimisation which skips fix_sentence_endings.  
Commenting it out seems to fix the problem.

----------------------------------------------------------------------

>Comment By: Neal Norwitz (nnorwitz)
Date: 2003-11-24 14:53

Message:
Logged In: YES 
user_id=33168

Greg, any comments?  You implemented textwrap IIRC.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=847346&group_id=5470



More information about the Python-bugs-list mailing list