summaryrefslogtreecommitdiff
path: root/coverage/phystokens.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2022-11-06 15:51:44 -0500
committerNed Batchelder <ned@nedbatchelder.com>2022-11-06 16:16:04 -0500
commit556344babd5210c093eba547d1b15489843f4359 (patch)
tree5ea9c3f84044722f116ebbfad4bb66cda91b8a87 /coverage/phystokens.py
parentfaaf0d45abcf0a11c9e5db144c5b79f581dd92eb (diff)
downloadpython-coveragepy-git-556344babd5210c093eba547d1b15489843f4359.tar.gz
refactor: no need for special handling of compiling unicode source
This was a holdover from Python 2 days.
Diffstat (limited to 'coverage/phystokens.py')
-rw-r--r--coverage/phystokens.py30
1 files changed, 0 insertions, 30 deletions
diff --git a/coverage/phystokens.py b/coverage/phystokens.py
index c6dc1e0a..07ad5349 100644
--- a/coverage/phystokens.py
+++ b/coverage/phystokens.py
@@ -184,8 +184,6 @@ class CachedTokenizer:
generate_tokens = CachedTokenizer().generate_tokens
-COOKIE_RE = re.compile(r"^[ \t]*#.*coding[:=][ \t]*([-\w.]+)", flags=re.MULTILINE)
-
@contract(source='bytes')
def source_encoding(source):
"""Determine the encoding for `source`, according to PEP 263.
@@ -197,31 +195,3 @@ def source_encoding(source):
"""
readline = iter(source.splitlines(True)).__next__
return tokenize.detect_encoding(readline)[0]
-
-
-@contract(source='unicode')
-def compile_unicode(source, filename, mode):
- """Just like the `compile` builtin, but works on any Unicode string.
-
- Python 2's compile() builtin has a stupid restriction: if the source string
- is Unicode, then it may not have a encoding declaration in it. Why not?
- Who knows! It also decodes to utf-8, and then tries to interpret those
- utf-8 bytes according to the encoding declaration. Why? Who knows!
-
- This function neuters the coding declaration, and compiles it.
-
- """
- source = neuter_encoding_declaration(source)
- code = compile(source, filename, mode)
- return code
-
-
-@contract(source='unicode', returns='unicode')
-def neuter_encoding_declaration(source):
- """Return `source`, with any encoding declaration neutered."""
- if COOKIE_RE.search(source):
- source_lines = source.splitlines(True)
- for lineno in range(min(2, len(source_lines))):
- source_lines[lineno] = COOKIE_RE.sub("# (deleted declaration)", source_lines[lineno])
- source = "".join(source_lines)
- return source