On Saturday, November 12, 2016 at 12:32:55 PM UTC-6, Terry Brown wrote:
>
> That tripped me up too, empty strings are OK if you're using 'not
> s.isspace()'.
>
It works both ways. s.lstrip() can be wrong, wrong, wrong, as this
morning's bug fix in i.check shows.
The new i.lstrip_line helper gets it right:
def lstrip_line(self, s):
'''Delete leading whitespace, *without* deleting the trailing
newline!'''
# This fixes a major bug in i.strip_lws.
assert s, g.callers()
return '\n' if s.isspace() else s.lstrip()
The bug in i.check was serious. In essence, it caused i.check to ignored
all blank lines! And it masked a similar bug in the xml importer.
While making i.check line-oriented (more about this in another post) I came
across this code:
def strip_lws(self, lines):
'''Strip leading whitespace from all lines of s.'''
return ''.join([z.lstrip() for z in g.splitLines(s)])
Because of our conversation here, I realized that this was wrong, wrong,
wrong. Thank you, Terry and Reinhard, for burning this issue into my
consciousness!
Eventually, the code got replaced with:
def strip_lws(self, lines):
'''Strip leading whitespace from all lines of s.'''
return [self.lstrip_line(z) for z in lines]
All this goes to show that the i.check's helpers should be covered by unit
tests!
Edward
>
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.