From 29f89cc75ab2bc7937f167b01054e587f8944faa Mon Sep 17 00:00:00 2001 From: David Halter Date: Thu, 18 Jul 2013 16:55:19 +0200 Subject: [PATCH] finally fixed a unicode problem that existed for a longer time --- jedi/_compatibility.py | 10 ++++++++++ jedi/debug.py | 5 +++-- jedi/evaluate.py | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/jedi/_compatibility.py b/jedi/_compatibility.py index 125b76f8..1f839c8a 100644 --- a/jedi/_compatibility.py +++ b/jedi/_compatibility.py @@ -161,3 +161,13 @@ try: encoding = 'utf-8' except AttributeError: encoding = 'ascii' + +def u(string): + """Cast to unicode DAMMIT! + Written because Python2 repr always implicitly casts to a string, so we + have to cast back to a unicode (and we now that we always deal with valid + unicode, because we check that in the beginning). + """ + if not is_py3k and not isinstance(string, unicode): + return unicode(str(string), 'UTF-8') + return string diff --git a/jedi/debug.py b/jedi/debug.py index 6ab00b33..e4d2f670 100644 --- a/jedi/debug.py +++ b/jedi/debug.py @@ -1,3 +1,4 @@ +from _compatibility import u import inspect import time @@ -36,12 +37,12 @@ def dbg(*args): frm = inspect.stack()[1] mod = inspect.getmodule(frm[0]) if not (mod.__name__ in ignored_modules): - debug_function(NOTICE, 'dbg: ' + ', '.join(str(a) for a in args)) + debug_function(NOTICE, 'dbg: ' + ', '.join(u(a) for a in args)) def warning(*args): if debug_function and enable_warning: - debug_function(WARNING, 'warning: ' + ', '.join(str(a) for a in args)) + debug_function(WARNING, 'warning: ' + ', '.join(u(a) for a in args)) def speed(name): diff --git a/jedi/evaluate.py b/jedi/evaluate.py index 013a561f..5066bdb3 100644 --- a/jedi/evaluate.py +++ b/jedi/evaluate.py @@ -73,7 +73,7 @@ from __future__ import with_statement import sys import itertools -from jedi._compatibility import next, hasattr, is_py3k, unicode, reraise +from jedi._compatibility import next, hasattr, is_py3k, unicode, reraise, u from jedi import common from jedi import cache from jedi import parsing_representation as pr @@ -427,7 +427,7 @@ def find_name(scope, name_str, position=None, search_global=False, # __getattr__ / __getattribute__ result += check_getattr(nscope, name_str) debug.dbg('sfn filter "%s" in (%s-%s): %s@%s' % (name_str, scope, - nscope, result, position)) + nscope, u(result), position)) return result def descriptor_check(result):