diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2014-11-29 08:55:08 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2014-11-29 08:55:08 -0500 |
commit | e168b24eb66a8f9cd2aa17d1041d43a675d2cfa4 (patch) | |
tree | 9b94d7e7a5dc1ba00fe8edcc918435dd49a82bf7 /coverage/parser.py | |
parent | 8daa8515ccd83355669b0a70ffa74201ec69f6de (diff) | |
download | python-coveragepy-e168b24eb66a8f9cd2aa17d1041d43a675d2cfa4.tar.gz |
Don't be confused by files with missing final newlines. #293
Diffstat (limited to 'coverage/parser.py')
-rw-r--r-- | coverage/parser.py | 14 |
1 files changed, 8 insertions, 6 deletions
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" % |