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 | 5c4bbc3e0fc3d1a1cb0dffae37d4de6f3b29613e (patch) | |
tree | 29c7ed6e4b78e26dc04b7cf4e44c42f642a235be /coverage/phystokens.py | |
parent | 5d725e5e3280387feb24ea6112eea339ed8d3571 (diff) | |
download | python-coveragepy-git-5c4bbc3e0fc3d1a1cb0dffae37d4de6f3b29613e.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 7092d39e..5d2ccfc7 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 |