From e168b24eb66a8f9cd2aa17d1041d43a675d2cfa4 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 29 Nov 2014 08:55:08 -0500 Subject: Don't be confused by files with missing final newlines. #293 --- coverage/parser.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'coverage/parser.py') diff --git a/coverage/parser.py b/coverage/parser.py index ae36a73..ef2ee5b 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -49,9 +49,13 @@ class PythonParser(CodeParser): "No source for code: '%s': %s" % (self.filename, err) ) - # Scrap the BOM if it exists. - if self.text and ord(self.text[0]) == 0xfeff: - self.text = self.text[1:] + if self.text: + # Scrap the BOM if it exists. + if ord(self.text[0]) == 0xfeff: + self.text = self.text[1:] + # Python source should always have a final newline. + if self.text[-1] != "\n": + self.text += "\n" self.exclude = exclude @@ -346,9 +350,7 @@ class ByteParser(object): self.text = text try: - # Python 2.3 and 2.4 don't like partial last lines, so be sure - # the text ends nicely for them. - self.code = compile(text + '\n', filename, "exec") + self.code = compile(text, filename, "exec") except SyntaxError as synerr: raise NotPython( "Couldn't parse '%s' as Python source: '%s' at line %d" % -- cgit v1.2.1