From c731debc01e436609b73248f6dfd9581d039fc1a Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 16 Oct 2015 21:00:59 -0400 Subject: Do a better job decoding source files. #431 --- coverage/phystokens.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'coverage/phystokens.py') 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 -- cgit v1.2.1