diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-10-16 21:00:59 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-10-16 21:00:59 -0400 |
commit | c731debc01e436609b73248f6dfd9581d039fc1a (patch) | |
tree | 709e551020ff2b6dd2a12e081fb14a1053e74204 /coverage/phystokens.py | |
parent | 9f269ac30b46038ee1fec1c89fb5b5fef5ce6678 (diff) | |
download | python-coveragepy-c731debc01e436609b73248f6dfd9581d039fc1a.tar.gz |
Do a better job decoding source files. #431
Diffstat (limited to 'coverage/phystokens.py')
-rw-r--r-- | coverage/phystokens.py | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/coverage/phystokens.py b/coverage/phystokens.py index 7092d39..5d2ccfc 100644 --- a/coverage/phystokens.py +++ b/coverage/phystokens.py @@ -274,20 +274,14 @@ def compile_unicode(source, filename, mode): 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! + Who knows! It also decodes to utf8, and then tries to interpret those utf8 + bytes according to the encoding declaration. Why? Who knows! - This function catches that exception, neuters the coding declaration, and - compiles it anyway. + This function neuters the coding declaration, and compiles it. """ - try: - code = compile(source, filename, mode) - except SyntaxError as synerr: - if "coding declaration in unicode string" not in synerr.args[0].lower(): - raise - source = neuter_encoding_declaration(source) - code = compile(source, filename, mode) - + source = neuter_encoding_declaration(source) + code = compile(source, filename, mode) return code |