diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2022-12-23 09:23:55 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2022-12-23 10:07:53 -0500 |
commit | 35e249ff74cfcbc44889107cfcca785696dc4288 (patch) | |
tree | 69488c46c48f25c3830d33160220619bbdd9965f /coverage/phystokens.py | |
parent | 152cdc7a2b654b16fb572856d03097580e06e127 (diff) | |
download | python-coveragepy-git-35e249ff74cfcbc44889107cfcca785696dc4288.tar.gz |
fix: certain strange characters caused reporting to fail. #1512
It turns out that str.splitlines() will break text on some characters
that file.readline() does not! Use readline() to read source files the
same way that Python does.
Diffstat (limited to 'coverage/phystokens.py')
-rw-r--r-- | coverage/phystokens.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/coverage/phystokens.py b/coverage/phystokens.py index d1181939..2ced9de3 100644 --- a/coverage/phystokens.py +++ b/coverage/phystokens.py @@ -4,6 +4,7 @@ """Better tokenizing for coverage.py.""" import ast +import io import keyword import re import token @@ -172,7 +173,7 @@ class CachedTokenizer: """A stand-in for `tokenize.generate_tokens`.""" if text != self.last_text: self.last_text = text - readline = iter(text.splitlines(True)).__next__ + readline = io.StringIO(text).readline try: self.last_tokens = list(tokenize.generate_tokens(readline)) except: |