mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
it should be possible to find the origin of an operation, if it's a faulty one (static analysis)
This commit is contained in:
@@ -157,7 +157,7 @@ class NameFinder(object):
|
|||||||
else:
|
else:
|
||||||
p = precedence.create_precedence(expression_list)
|
p = precedence.create_precedence(expression_list)
|
||||||
if (isinstance(p, precedence.Precedence)
|
if (isinstance(p, precedence.Precedence)
|
||||||
and p.operator == 'is not'
|
and p.operator.string == 'is not'
|
||||||
and p.right.get_code() == 'None'
|
and p.right.get_code() == 'None'
|
||||||
and p.left.get_code() == unicode(self.name_str)):
|
and p.left.get_code() == unicode(self.name_str)):
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class Precedence(object):
|
|||||||
which = which.value
|
which = which.value
|
||||||
return which
|
return which
|
||||||
|
|
||||||
return (process(self.left), self.operator, process(self.right))
|
return (process(self.left), self.operator.string, process(self.right))
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '(%s %s %s)' % (self.left, self.operator, self.right)
|
return '(%s %s %s)' % (self.left, self.operator, self.right)
|
||||||
@@ -114,6 +114,21 @@ def _get_number(iterator, priority=PythonGrammar.LOWEST_PRIORITY):
|
|||||||
return el
|
return el
|
||||||
|
|
||||||
|
|
||||||
|
class MergedOperator(pr.Operator):
|
||||||
|
"""
|
||||||
|
A way to merge the two operators `is not` and `not int`, which are two
|
||||||
|
words instead of one.
|
||||||
|
Maybe there's a better way (directly in the tokenizer/parser? but for now
|
||||||
|
this is fine.)
|
||||||
|
"""
|
||||||
|
def __init__(self, first, second):
|
||||||
|
string = first.string + ' ' + second.string
|
||||||
|
super(MergedOperator, self).__init__(string, first.start_pos)
|
||||||
|
|
||||||
|
self.first = first
|
||||||
|
self.second = second
|
||||||
|
|
||||||
|
|
||||||
def _check_operator(iterator, priority=PythonGrammar.LOWEST_PRIORITY):
|
def _check_operator(iterator, priority=PythonGrammar.LOWEST_PRIORITY):
|
||||||
try:
|
try:
|
||||||
left = _get_number(iterator, priority)
|
left = _get_number(iterator, priority)
|
||||||
@@ -140,14 +155,14 @@ def _check_operator(iterator, priority=PythonGrammar.LOWEST_PRIORITY):
|
|||||||
match = check[match_index]
|
match = check[match_index]
|
||||||
if isinstance(match, PythonGrammar.MultiPart):
|
if isinstance(match, PythonGrammar.MultiPart):
|
||||||
next_tok = next(iterator)
|
next_tok = next(iterator)
|
||||||
if next_tok != match.second:
|
if next_tok == match.second:
|
||||||
|
el = MergedOperator(el, next_tok)
|
||||||
|
else:
|
||||||
iterator.push_back(next_tok)
|
iterator.push_back(next_tok)
|
||||||
if el == 'is': # `is not` special case
|
if el == 'not':
|
||||||
match = 'is'
|
|
||||||
else:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
operator = match
|
operator = el
|
||||||
break
|
break
|
||||||
|
|
||||||
if operator is None:
|
if operator is None:
|
||||||
@@ -171,9 +186,9 @@ def _check_operator(iterator, priority=PythonGrammar.LOWEST_PRIORITY):
|
|||||||
_syntax_error(iterator.current, 'SyntaxError operand missing')
|
_syntax_error(iterator.current, 'SyntaxError operand missing')
|
||||||
else:
|
else:
|
||||||
if operator in PythonGrammar.TERNARY:
|
if operator in PythonGrammar.TERNARY:
|
||||||
left = TernaryPrecedence(left, str(operator), right, middle)
|
left = TernaryPrecedence(left, operator, right, middle)
|
||||||
else:
|
else:
|
||||||
left = Precedence(left, str(operator), right)
|
left = Precedence(left, operator, right)
|
||||||
return left
|
return left
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
1 + 1
|
-1 + 1
|
||||||
1 + 1.0
|
1 + 1.0
|
||||||
#! 6 type-error-operation
|
#! 6 type-error-operation
|
||||||
1 + '1'
|
1 + '1'
|
||||||
|
|||||||
Reference in New Issue
Block a user