mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-19 23:09:43 +08:00
Operator fixes. Subclass of Simple, now.
This commit is contained in:
+1
-1
@@ -243,7 +243,7 @@ def save_parser(path, name, parser, pickling=True):
|
|||||||
|
|
||||||
class ParserPickling(object):
|
class ParserPickling(object):
|
||||||
|
|
||||||
version = 12
|
version = 13
|
||||||
"""
|
"""
|
||||||
Version number (integer) for file system cache.
|
Version number (integer) for file system cache.
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class CompiledObject(Base):
|
|||||||
for p in tokens:
|
for p in tokens:
|
||||||
parts = [FakeName(part) for part in p.strip().split('=')]
|
parts = [FakeName(part) for part in p.strip().split('=')]
|
||||||
if len(parts) >= 2:
|
if len(parts) >= 2:
|
||||||
parts.insert(1, Operator('=', (0, 0)))
|
parts.insert(1, Operator(module, '=', module, (0, 0)))
|
||||||
params.append(Param(module, parts, start_pos,
|
params.append(Param(module, parts, start_pos,
|
||||||
end_pos, builtin))
|
end_pos, builtin))
|
||||||
return params
|
return params
|
||||||
|
|||||||
@@ -123,8 +123,8 @@ class MergedOperator(pr.Operator):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, first, second):
|
def __init__(self, first, second):
|
||||||
string = first.string + ' ' + second.string
|
string = first.string + ' ' + second.string
|
||||||
super(MergedOperator, self).__init__(string, first.start_pos)
|
super(MergedOperator, self).__init__(first._sub_module, string,
|
||||||
|
first.parent, first.start_pos)
|
||||||
self.first = first
|
self.first = first
|
||||||
self.second = second
|
self.second = second
|
||||||
|
|
||||||
@@ -278,7 +278,7 @@ def _element_calculate(evaluator, left, operator, right):
|
|||||||
# Static analysis, one is a number, the other one is not.
|
# Static analysis, one is a number, the other one is not.
|
||||||
elif l_is_num != r_is_num:
|
elif l_is_num != r_is_num:
|
||||||
message = "TypeError: unsupported operand type(s) for +: %s and %s"
|
message = "TypeError: unsupported operand type(s) for +: %s and %s"
|
||||||
analysis.add(evaluator, 'type-error-operation', right,
|
analysis.add(evaluator, 'type-error-operation', operator,
|
||||||
message % (left, right))
|
message % (left, right))
|
||||||
elif operator == '-':
|
elif operator == '-':
|
||||||
if _is_number(left) and _is_number(right):
|
if _is_number(left) and _is_number(right):
|
||||||
|
|||||||
@@ -325,7 +325,9 @@ class Parser(object):
|
|||||||
# print 'parse_stmt', tok, tokenize.tok_name[token_type]
|
# print 'parse_stmt', tok, tokenize.tok_name[token_type]
|
||||||
is_kw = tok.string in OPERATOR_KEYWORDS
|
is_kw = tok.string in OPERATOR_KEYWORDS
|
||||||
if tok.type == tokenize.OP or is_kw:
|
if tok.type == tokenize.OP or is_kw:
|
||||||
tok_list.append(pr.Operator(tok.string, tok.start_pos))
|
tok_list.append(
|
||||||
|
pr.Operator(self.module, tok.string, self._scope, tok.start_pos)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
tok_list.append(tok)
|
tok_list.append(tok)
|
||||||
|
|
||||||
|
|||||||
@@ -918,7 +918,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, Operator)) else unicode(c)
|
isinstance(c, tokenize.Token) 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)
|
||||||
@@ -1565,26 +1565,21 @@ class ListComprehension(ForFlow):
|
|||||||
return "%s for %s in %s" % tuple(code)
|
return "%s for %s in %s" % tuple(code)
|
||||||
|
|
||||||
|
|
||||||
class Operator(Base):
|
class Operator(Simple):
|
||||||
__slots__ = ('string', '_line', '_column')
|
__slots__ = ('string',)
|
||||||
|
|
||||||
def __init__(self, string, start_pos):
|
def __init__(self, module, string, parent, start_pos):
|
||||||
# TODO needs module param
|
end_pos = start_pos[0], start_pos[1] + len(string)
|
||||||
|
super(Operator, self).__init__(module, start_pos, end_pos)
|
||||||
self.string = string
|
self.string = string
|
||||||
self._line = start_pos[0]
|
self.parent = parent
|
||||||
self._column = start_pos[1]
|
|
||||||
|
def get_code(self):
|
||||||
|
return self.string
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s: `%s`>" % (type(self).__name__, self.string)
|
return "<%s: `%s`>" % (type(self).__name__, self.string)
|
||||||
|
|
||||||
@property
|
|
||||||
def start_pos(self):
|
|
||||||
return self._line, self._column
|
|
||||||
|
|
||||||
@property
|
|
||||||
def end_pos(self):
|
|
||||||
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.string == other
|
return self.string == other
|
||||||
|
|||||||
Reference in New Issue
Block a user