1
0
forked from VimPlug/jedi

more unicode switches in the parser

This commit is contained in:
Dave Halter
2014-02-25 14:27:50 +01:00
parent f4f79317fe
commit aea2c4620f
3 changed files with 11 additions and 35 deletions

View File

@@ -550,7 +550,7 @@ class Function(Scope):
:rtype: str :rtype: str
""" """
l = str(funcname or self.name.names[-1]) + '(' l = unicode(funcname or self.name.names[-1]) + '('
lines = [] lines = []
for (i, p) in enumerate(self.params): for (i, p) in enumerate(self.params):
code = p.get_code(False) code = p.get_code(False)
@@ -753,7 +753,7 @@ class Import(Simple):
if self.alias: if self.alias:
ns_str = "%s as %s" % (namespace, alias) ns_str = "%s as %s" % (namespace, alias)
else: else:
ns_str = str(namespace) ns_str = unicode(namespace)
nl = '\n' if new_line else '' nl = '\n' if new_line else ''
if self.from_ns or self.relative_count: if self.from_ns or self.relative_count:
@@ -1463,7 +1463,7 @@ class Name(Simple):
def get_code(self): def get_code(self):
""" Returns the names in a full string format """ """ 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 @property
def docstr(self): def docstr(self):

View File

@@ -19,8 +19,6 @@ class Token(object):
>>> tuple(Token(1,2,3,4)) >>> tuple(Token(1,2,3,4))
(1, 2, (3, 4)) (1, 2, (3, 4))
>>> unicode(Token(1, "test", 1, 1)) == "test"
True
>>> repr(Token(1, "test", 1, 1)) >>> repr(Token(1, "test", 1, 1))
"<Token: (1, 'test', (1, 1))>" "<Token: (1, 'test', (1, 1))>"
>>> Token(1, 2, 3, 4).__getstate__() >>> Token(1, 2, 3, 4).__getstate__()
@@ -37,10 +35,10 @@ class Token(object):
4 4
>>> Token.from_tuple((6, 5, (4, 3))) >>> Token.from_tuple((6, 5, (4, 3)))
<Token: (6, 5, (4, 3))> <Token: (6, 5, (4, 3))>
>>> unicode(Token(1, u("😷"), 1 ,1)) + "p" == u("😷p") >>> Token(1, u("😷"), 1 ,1).string + "p" == u("😷p")
True True
""" """
__slots__ = ("_type", "_token", "_start_pos_line", "_start_pos_col") __slots__ = ("_type", "string", "_start_pos_line", "_start_pos_col")
@classmethod @classmethod
def from_tuple(cls, tp): def from_tuple(cls, tp):
@@ -50,7 +48,7 @@ class Token(object):
self, type, token, start_pos_line, start_pos_col self, type, token, start_pos_line, start_pos_col
): ):
self._type = type self._type = type
self._token = token self.string = token
self._start_pos_line = start_pos_line self._start_pos_line = start_pos_line
self._start_pos_col = start_pos_col self._start_pos_col = start_pos_col
@@ -59,17 +57,11 @@ class Token(object):
# Backward compatibility py2 # Backward compatibility py2
def __unicode__(self): def __unicode__(self):
return self.as_string() return self.string
# Backward compatibility py3 # Backward compatibility py3
def __str__(self): def __str__(self):
return self.as_string() return self.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)
# Backward compatibility # Backward compatibility
def __getitem__(self, key): def __getitem__(self, key):
@@ -89,7 +81,7 @@ class Token(object):
@property @property
def token(self): def token(self):
return self._token return self.string
@property @property
def start_pos_line(self): def start_pos_line(self):
@@ -128,7 +120,7 @@ class Token(object):
def __setstate__(self, state): def __setstate__(self, state):
self._type = state[0] self._type = state[0]
self._token = state[1] self.string = state[1]
self._start_pos_line = state[2] self._start_pos_line = state[2]
self._start_pos_col = state[3] self._start_pos_col = state[3]

View File

@@ -44,8 +44,6 @@ class TokenInfo(object):
>>> tuple(TokenInfo(1, 'foo' ,(3,4))) >>> tuple(TokenInfo(1, 'foo' ,(3,4)))
(1, 'foo', (3, 4), (3, 7)) (1, 'foo', (3, 4), (3, 7))
>>> str(TokenInfo(1, "test", (1, 1))) == "test"
True
>>> repr(TokenInfo(1, "test", (1, 1))) >>> repr(TokenInfo(1, "test", (1, 1)))
"<TokenInfo: (1, 'test', (1, 1))>" "<TokenInfo: (1, 'test', (1, 1))>"
>>> TokenInfo(1, 'bar', (3, 4)).__getstate__() >>> TokenInfo(1, 'bar', (3, 4)).__getstate__()
@@ -60,7 +58,7 @@ class TokenInfo(object):
'foo' 'foo'
>>> a._start_pos_col >>> a._start_pos_col
4 4
>>> unicode(TokenInfo(1, u("😷"), (1 ,1))) + "p" == u("😷p") >>> TokenInfo(1, u("😷"), (1 ,1)).string + "p" == u("😷p")
True True
""" """
__slots__ = ("type", "string", "_start_pos_line", "_start_pos_col") __slots__ = ("type", "string", "_start_pos_line", "_start_pos_col")
@@ -74,20 +72,6 @@ class TokenInfo(object):
def __repr__(self): def __repr__(self):
return "<%s: %s>" % (type(self).__name__, tuple(self)[:3]) 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 # Backward compatibility
def __getitem__(self, key): def __getitem__(self, key):
# Builds the same structure as tuple used to have # Builds the same structure as tuple used to have