1
0
forked from VimPlug/jedi

fix get_code method for Operator (still ugly, though)

This commit is contained in:
Dave Halter
2014-02-26 22:23:21 +01:00
parent 3330e29748
commit fdabca20e9
3 changed files with 17 additions and 17 deletions

View File

@@ -322,10 +322,10 @@ class Evaluator(object):
# Only the first command is important, the rest should basically not # Only the first command is important, the rest should basically not
# happen except in broken code (e.g. docstrings that aren't code). # happen except in broken code (e.g. docstrings that aren't code).
call = expression_list[0] call = expression_list[0]
if isinstance(call, (str, unicode)): if isinstance(call, pr.Call):
call_path = [call]
else:
call_path = list(call.generate_call_path()) call_path = list(call.generate_call_path())
else:
call_path = [call]
scope = stmt.get_parent_until(pr.IsScope) scope = stmt.get_parent_until(pr.IsScope)
pos = stmt.start_pos pos = stmt.start_pos

View File

@@ -30,7 +30,7 @@ def sys_path_with_modifications(module):
try: try:
exec_function(c % code, variables) exec_function(c % code, variables)
except Exception: except Exception:
debug.warning('sys path detected, but failed to evaluate') debug.warning('sys.path manipulation detected, but failed to evaluate.')
return None return None
try: try:
res = variables['result'] res = variables['result']

View File

@@ -844,7 +844,7 @@ class Statement(Simple, DocstringMixin):
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 c.string if pieces = [c.get_code() if isinstance(c, Simple) else c.string if
isinstance(c, tokenize.Token) else unicode(c) isinstance(c, (tokenize.Token, Operator)) 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)
@@ -924,8 +924,8 @@ isinstance(c, tokenize.Token) else unicode(c)
it and make it nicer, that would be cool :-) it and make it nicer, that would be cool :-)
""" """
def is_assignment(tok): def is_assignment(tok):
return isinstance(tok, Operator) and tok.operator.endswith('=') \ return isinstance(tok, Operator) and tok.string.endswith('=') \
and not tok.operator in ['>=', '<=', '==', '!='] and not tok.string in ['>=', '<=', '==', '!=']
def parse_array(token_iterator, array_type, start_pos, add_el=None, def parse_array(token_iterator, array_type, start_pos, add_el=None,
added_breaks=()): added_breaks=()):
@@ -1118,7 +1118,7 @@ isinstance(c, tokenize.Token) else unicode(c)
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((result, tok.operator)) self._assignment_details.append((result, tok.string))
result = [] result = []
is_chain = False is_chain = False
continue continue
@@ -1150,7 +1150,7 @@ isinstance(c, tokenize.Token) else unicode(c)
is_chain = False is_chain = False
elif tok in brackets.keys(): elif tok in brackets.keys():
arr, is_ass = parse_array( arr, is_ass = parse_array(
token_iterator, brackets[tok.operator], start_pos token_iterator, brackets[tok.string], start_pos
) )
if result and isinstance(result[-1], StatementElement): if result and isinstance(result[-1], StatementElement):
result[-1].set_execution(arr) result[-1].set_execution(arr)
@@ -1512,15 +1512,15 @@ class ListComprehension(Base):
class Operator(Base): class Operator(Base):
__slots__ = ('operator', '_line', '_column') __slots__ = ('string', '_line', '_column')
def __init__(self, operator, start_pos): def __init__(self, string, start_pos):
self.operator = operator self.string = string
self._line = start_pos[0] self._line = start_pos[0]
self._column = start_pos[1] self._column = start_pos[1]
def __repr__(self): def __repr__(self):
return "<%s: `%s`>" % (type(self).__name__, self.operator) return "<%s: `%s`>" % (type(self).__name__, self.string)
@property @property
def start_pos(self): def start_pos(self):
@@ -1528,15 +1528,15 @@ class Operator(Base):
@property @property
def end_pos(self): def end_pos(self):
return self._line, self._column + len(self.operator) return self._line, self._column + len(self.string)
def __eq__(self, other): def __eq__(self, other):
"""Make comparisons easy. Improves the readability of the parser.""" """Make comparisons easy. Improves the readability of the parser."""
return self.operator == other return self.string == other
def __ne__(self, other): def __ne__(self, other):
"""Python 2 compatibility.""" """Python 2 compatibility."""
return self.operator != other return self.string != other
def __hash__(self): def __hash__(self):
return hash(self.operator) return hash(self.string)