From 15510a4c3b2b751a333cdc36821a3682db49f01e Mon Sep 17 00:00:00 2001 From: David Halter Date: Wed, 19 Dec 2012 18:46:32 +0100 Subject: [PATCH] more unicode casts instead of str casts --- jedi/api.py | 6 +++--- jedi/api_classes.py | 21 +++++++++++---------- jedi/parsing.py | 8 ++++---- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/jedi/api.py b/jedi/api.py index 535df83a..3a138eac 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -285,14 +285,14 @@ class Script(object): if next(context) in ('class', 'def'): user_scope = self.parser.user_scope definitions = set([user_scope.name]) - search_name = str(user_scope.name) + search_name = unicode(user_scope.name) elif isinstance(self.parser.user_stmt, parsing.Import): s, name_part = self._get_on_import_stmt() try: definitions = [s.follow(is_goto=True)[0]] except IndexError: definitions = [] - search_name = str(name_part) + search_name = unicode(name_part) if add_import_name: import_name = self.parser.user_stmt.get_defined_names() @@ -320,7 +320,7 @@ class Script(object): and self.pos < user_stmt.get_assignment_calls().start_pos: # the search_name might be before `=` definitions = [v for v in user_stmt.set_vars - if str(v) == search_name] + if unicode(v) == search_name] if not isinstance(user_stmt, parsing.Import): # import case is looked at with add_import_name option definitions = dynamic.related_name_add_import_modules(definitions, diff --git a/jedi/api_classes.py b/jedi/api_classes.py index 793f806a..f7b7df3c 100644 --- a/jedi/api_classes.py +++ b/jedi/api_classes.py @@ -3,6 +3,7 @@ import re import os +from _compatibility import unicode import cache import dynamic import helpers @@ -51,7 +52,7 @@ class BaseDefinition(object): self.is_keyword = isinstance(definition, keywords.Keyword) # generate a path to the definition - self.module_path = str(definition.get_parent_until().path) + self.module_path = unicode(definition.get_parent_until().path) @property def type(self): @@ -104,20 +105,20 @@ class BaseDefinition(object): def raw_doc(self): """ Returns the raw docstring `__doc__` for any object """ try: - return str(self.definition.docstr) + return unicode(self.definition.docstr) except AttributeError: return '' @property def description(self): - return str(self.definition) + return unicode(self.definition) @property def full_name(self): """ Returns the path to a certain class/function, see #61. """ - path = [str(p) for p in self.path] + path = [unicode(p) for p in self.path] # TODO add further checks, the mapping should only occur on stdlib. try: path[0] = self._mapping[path[0]] @@ -174,7 +175,7 @@ class Completion(BaseDefinition): would return 'isinstance'. """ - return str(self.name.names[-1]) + return unicode(self.name.names[-1]) @property def description(self): @@ -187,7 +188,7 @@ class Completion(BaseDefinition): if t == 'Statement' or t == 'Import': desc = self.definition.get_code(False) else: - desc = '.'.join(str(p) for p in self.path) + desc = '.'.join(unicode(p) for p in self.path) line_nr = '' if self.in_builtin_module else '@%s' % self.line_nr return '%s: %s%s' % (t, desc, line_nr) @@ -237,9 +238,9 @@ class Definition(BaseDefinition): if isinstance(d, evaluate.Array): d = 'class ' + d.type elif isinstance(d, (parsing.Class, evaluate.Class, evaluate.Instance)): - d = 'class ' + str(d.name) + d = 'class ' + unicode(d.name) elif isinstance(d, (evaluate.Function, evaluate.parsing.Function)): - d = 'def ' + str(d.name) + d = 'def ' + unicode(d.name) elif isinstance(d, evaluate.parsing.Module): # only show module name d = 'module %s' % self.module_name @@ -268,7 +269,7 @@ class RelatedName(BaseDefinition): def __init__(self, name_part, scope): super(RelatedName, self).__init__(scope, name_part.start_pos) self.name_part = name_part - self.text = str(name_part) + self.text = unicode(name_part) self.end_pos = name_part.end_pos @property @@ -317,7 +318,7 @@ class CallDef(object): @property def call_name(self): """ The name (e.g. 'isinstance') as a string. """ - return str(self.executable.name) + return unicode(self.executable.name) @property def module(self): diff --git a/jedi/parsing.py b/jedi/parsing.py index 251ece7b..0a41c830 100644 --- a/jedi/parsing.py +++ b/jedi/parsing.py @@ -29,7 +29,7 @@ as input and ignores just all the non-python stuff. Basically you could feed it a perl script, and it should still work (which means throw no error). TODO remove docstr params from Scope.__init__() """ -from _compatibility import (next, literal_eval, StringIO, +from _compatibility import (next, literal_eval, StringIO, unicode, property, cleandoc, Python3Method) import tokenize @@ -1471,7 +1471,7 @@ class PyFuzzyParser(object): :rtype: (Statement, str) """ - string = '' + string = unicode('') set_vars = [] used_funcs = [] used_vars = [] @@ -1634,7 +1634,7 @@ class PyFuzzyParser(object): def __next__(self): """ Generate the next tokenize pattern. """ try: - type, tok, self.start_pos, self.end_pos, \ + typ, tok, self.start_pos, self.end_pos, \ self.parserline = next(self.gen) except (StopIteration, common.MultiLevelStopIteration): # on finish, set end_pos correctly @@ -1651,7 +1651,7 @@ class PyFuzzyParser(object): (self.parserline.replace('\n', ''), repr(self.scope))) self.user_scope = self.scope self.last_token = self.current - self.current = (type, tok) + self.current = (typ, tok) return self.current def parse(self):