summaryrefslogtreecommitdiff
path: root/coverage/phystokens.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-12-28 08:45:17 -0500
committerNed Batchelder <ned@nedbatchelder.com>2014-12-28 08:45:17 -0500
commit9ee742b38e6610bb3290bd4680723ea47eeac181 (patch)
tree51bee3606f9fb81c2812eaa0126aa852c844cd72 /coverage/phystokens.py
parent335e87c11f636c89fe545b6e7026c4771ab8c79e (diff)
downloadpython-coveragepy-9ee742b38e6610bb3290bd4680723ea47eeac181.tar.gz
Make source_encoding stricter about its arguments, and test it everywhere
Diffstat (limited to 'coverage/phystokens.py')
-rw-r--r--coverage/phystokens.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/coverage/phystokens.py b/coverage/phystokens.py
index bf55e8a..9577625 100644
--- a/coverage/phystokens.py
+++ b/coverage/phystokens.py
@@ -148,11 +148,17 @@ generate_tokens = CachedTokenizer().generate_tokens
def _source_encoding_py2(source):
- """Determine the encoding for `source` (a string), according to PEP 263.
+ """Determine the encoding for `source`, according to PEP 263.
- Returns a string, the name of the encoding.
+ Arguments:
+ source (byte string): the text of the program.
+
+ Returns:
+ string: the name of the encoding.
"""
+ assert isinstance(source, bytes)
+
# Do this so the detect_encode code we copied will work.
readline = iter(source.splitlines(True)).next
@@ -240,11 +246,16 @@ def _source_encoding_py2(source):
def _source_encoding_py3(source):
- """Determine the encoding for `source` (a string), according to PEP 263.
+ """Determine the encoding for `source`, according to PEP 263.
+
+ Arguments:
+ source (byte string): the text of the program.
- Returns a string, the name of the encoding.
+ Returns:
+ string: the name of the encoding.
"""
+ assert isinstance(source, bytes)
readline = iter(source.splitlines(True)).__next__
return tokenize.detect_encoding(readline)[0]