summaryrefslogtreecommitdiff
path: root/coverage/parser.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-11-29 08:55:08 -0500
committerNed Batchelder <ned@nedbatchelder.com>2014-11-29 08:55:08 -0500
commit3f544ee33de31e96ca2d25d95da614e9a7a12f50 (patch)
tree55494ebfa947bcd81e24e91e94e960696fb96d61 /coverage/parser.py
parent025cc4ab92236971adc3961e0a177019fed2e6fd (diff)
downloadpython-coveragepy-git-3f544ee33de31e96ca2d25d95da614e9a7a12f50.tar.gz
Don't be confused by files with missing final newlines. #293
Diffstat (limited to 'coverage/parser.py')
-rw-r--r--coverage/parser.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/coverage/parser.py b/coverage/parser.py
index ae36a738..ef2ee5b8 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" %