1
0
forked from VimPlug/jedi

successfully removed __str__ and __unicode__ methods from token.Token

This commit is contained in:
Dave Halter
2014-02-25 16:21:53 +01:00
parent aea2c4620f
commit ee7108cc11
2 changed files with 8 additions and 16 deletions

View File

@@ -839,7 +839,8 @@ class Statement(Simple):
def get_code(self, new_line=True): def get_code(self, new_line=True):
def assemble(command_list, assignment=None): def assemble(command_list, assignment=None):
pieces = [c.get_code() if isinstance(c, Simple) else unicode(c) pieces = [c.get_code() if isinstance(c, Simple) else c.string if
isinstance(c, tokenize.TokenInfo) else unicode(c)
for c in command_list] for c in command_list]
if assignment is None: if assignment is None:
return ''.join(pieces) return ''.join(pieces)
@@ -888,7 +889,8 @@ class Statement(Simple):
def is_global(self): def is_global(self):
# first keyword of the first token is global -> must be a global # first keyword of the first token is global -> must be a global
return str(self.token_list[0]) == "global" tok = self.token_list[0]
return isinstance(tok, Name) and str(tok) == "global"
@property @property
def assignment_details(self): def assignment_details(self):
@@ -976,7 +978,7 @@ class Statement(Simple):
# it's not possible to set it earlier # it's not possible to set it earlier
tok.parent = self tok.parent = self
else: else:
tok = tok_temp.token tok = tok_temp.string
start_tok_pos = tok_temp.start_pos start_tok_pos = tok_temp.start_pos
last_end_pos = end_pos last_end_pos = end_pos
end_pos = tok_temp.end_pos end_pos = tok_temp.end_pos
@@ -1111,15 +1113,13 @@ class Statement(Simple):
end_pos = tok.end_pos end_pos = tok.end_pos
else: else:
token_type = tok_temp.type token_type = tok_temp.type
tok = tok_temp.token tok = tok_temp.string
start_pos = tok_temp.start_pos start_pos = tok_temp.start_pos
end_pos = tok_temp.end_pos end_pos = tok_temp.end_pos
if is_assignment(tok): if is_assignment(tok):
# This means, there is an assignment here. # This means, there is an assignment here.
# Add assignments, which can be more than one # Add assignments, which can be more than one
self._assignment_details.append( self._assignment_details.append((result, tok_temp.string))
(result, tok_temp.token)
)
result = [] result = []
is_chain = False is_chain = False
continue continue

View File

@@ -55,14 +55,6 @@ class Token(object):
def __repr__(self): def __repr__(self):
return "<%s: %s>" % (type(self).__name__, tuple(self)) return "<%s: %s>" % (type(self).__name__, tuple(self))
# Backward compatibility py2
def __unicode__(self):
return self.string
# Backward compatibility py3
def __str__(self):
return 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
@@ -99,7 +91,7 @@ class Token(object):
def end_pos(self): def end_pos(self):
"""Returns end position respecting multiline tokens.""" """Returns end position respecting multiline tokens."""
end_pos_line = self.start_pos_line end_pos_line = self.start_pos_line
lines = unicode(self).split('\n') lines = self.string.split('\n')
end_pos_line += len(lines) - 1 end_pos_line += len(lines) - 1
end_pos_col = self.start_pos_col end_pos_col = self.start_pos_col
# Check for multiline token # Check for multiline token