diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index 5ccc3136..23d7f702 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -550,7 +550,7 @@ class Function(Scope): :rtype: str """ - l = str(funcname or self.name.names[-1]) + '(' + l = unicode(funcname or self.name.names[-1]) + '(' lines = [] for (i, p) in enumerate(self.params): code = p.get_code(False) @@ -753,7 +753,7 @@ class Import(Simple): if self.alias: ns_str = "%s as %s" % (namespace, alias) else: - ns_str = str(namespace) + ns_str = unicode(namespace) nl = '\n' if new_line else '' if self.from_ns or self.relative_count: @@ -1463,7 +1463,7 @@ class Name(Simple): def get_code(self): """ Returns the names in a full string format """ - return ".".join(str(n) for n in self.names) + return ".".join(unicode(n) for n in self.names) @property def docstr(self): diff --git a/jedi/parser/token.py b/jedi/parser/token.py index 8bdcd815..db2ad705 100644 --- a/jedi/parser/token.py +++ b/jedi/parser/token.py @@ -19,8 +19,6 @@ class Token(object): >>> tuple(Token(1,2,3,4)) (1, 2, (3, 4)) - >>> unicode(Token(1, "test", 1, 1)) == "test" - True >>> repr(Token(1, "test", 1, 1)) "" >>> Token(1, 2, 3, 4).__getstate__() @@ -37,10 +35,10 @@ class Token(object): 4 >>> Token.from_tuple((6, 5, (4, 3))) - >>> unicode(Token(1, u("😷"), 1 ,1)) + "p" == u("😷p") + >>> Token(1, u("😷"), 1 ,1).string + "p" == u("😷p") True """ - __slots__ = ("_type", "_token", "_start_pos_line", "_start_pos_col") + __slots__ = ("_type", "string", "_start_pos_line", "_start_pos_col") @classmethod def from_tuple(cls, tp): @@ -50,7 +48,7 @@ class Token(object): self, type, token, start_pos_line, start_pos_col ): self._type = type - self._token = token + self.string = token self._start_pos_line = start_pos_line self._start_pos_col = start_pos_col @@ -59,17 +57,11 @@ class Token(object): # Backward compatibility py2 def __unicode__(self): - return self.as_string() + return self.string # Backward compatibility py3 def __str__(self): - return self.as_string() - - def as_string(self): - """For backward compatibilty str(token) or unicode(token) will work. - BUT please use as_string() instead, because it is independant from the - python version.""" - return unicode(self.token) + return self.string # Backward compatibility def __getitem__(self, key): @@ -89,7 +81,7 @@ class Token(object): @property def token(self): - return self._token + return self.string @property def start_pos_line(self): @@ -128,7 +120,7 @@ class Token(object): def __setstate__(self, state): self._type = state[0] - self._token = state[1] + self.string = state[1] self._start_pos_line = state[2] self._start_pos_col = state[3] diff --git a/jedi/parser/tokenize.py b/jedi/parser/tokenize.py index 3f465edf..0c96df95 100644 --- a/jedi/parser/tokenize.py +++ b/jedi/parser/tokenize.py @@ -44,8 +44,6 @@ class TokenInfo(object): >>> tuple(TokenInfo(1, 'foo' ,(3,4))) (1, 'foo', (3, 4), (3, 7)) - >>> str(TokenInfo(1, "test", (1, 1))) == "test" - True >>> repr(TokenInfo(1, "test", (1, 1))) "" >>> TokenInfo(1, 'bar', (3, 4)).__getstate__() @@ -60,7 +58,7 @@ class TokenInfo(object): 'foo' >>> a._start_pos_col 4 - >>> unicode(TokenInfo(1, u("😷"), (1 ,1))) + "p" == u("😷p") + >>> TokenInfo(1, u("😷"), (1 ,1)).string + "p" == u("😷p") True """ __slots__ = ("type", "string", "_start_pos_line", "_start_pos_col") @@ -74,20 +72,6 @@ class TokenInfo(object): def __repr__(self): return "<%s: %s>" % (type(self).__name__, tuple(self)[:3]) - # Backward compatibility py2 - def __unicode__(self): - return self.as_string() - - # Backward compatibility py3 - def __str__(self): - return self.as_string() - - def as_string(self): - """For backward compatibilty str(token) or unicode(token) will work. - BUT please use as_string() instead, because it is independent from the - python version.""" - return unicode(self.string) - # Backward compatibility def __getitem__(self, key): # Builds the same structure as tuple used to have