forked from VimPlug/jedi
More parser tree simplifications.
This commit is contained in:
@@ -154,10 +154,10 @@ class Evaluator(object):
|
|||||||
c_node = ContextualizedName(context, seek_name)
|
c_node = ContextualizedName(context, seek_name)
|
||||||
types = finder.check_tuple_assignments(self, c_node, types)
|
types = finder.check_tuple_assignments(self, c_node, types)
|
||||||
|
|
||||||
first_operation = stmt.first_operation()
|
first_operator = next(stmt.yield_operators(), None)
|
||||||
if first_operation not in ('=', None) and first_operation.type == 'operator':
|
if first_operator not in ('=', None) and first_operator.type == 'operator':
|
||||||
# `=` is always the last character in aug assignments -> -1
|
# `=` is always the last character in aug assignments -> -1
|
||||||
operator = copy.copy(first_operation)
|
operator = copy.copy(first_operator)
|
||||||
operator.value = operator.value[:-1]
|
operator.value = operator.value[:-1]
|
||||||
name = str(stmt.get_defined_names()[0])
|
name = str(stmt.get_defined_names()[0])
|
||||||
left = context.py__getattribute__(
|
left = context.py__getattribute__(
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ def _check_flow_information(context, flow, search_name, pos):
|
|||||||
for name in names:
|
for name in names:
|
||||||
ass = tree.search_ancestor(name, 'assert_stmt')
|
ass = tree.search_ancestor(name, 'assert_stmt')
|
||||||
if ass is not None:
|
if ass is not None:
|
||||||
result = _check_isinstance_type(context, ass.assertion(), search_name)
|
result = _check_isinstance_type(context, ass.assertion, search_name)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
@@ -965,6 +965,7 @@ class KeywordStatement(PythonBaseNode):
|
|||||||
class AssertStmt(KeywordStatement):
|
class AssertStmt(KeywordStatement):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
|
@property
|
||||||
def assertion(self):
|
def assertion(self):
|
||||||
return self.children[1]
|
return self.children[1]
|
||||||
|
|
||||||
@@ -972,9 +973,6 @@ class AssertStmt(KeywordStatement):
|
|||||||
class GlobalStmt(KeywordStatement):
|
class GlobalStmt(KeywordStatement):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
def get_defined_names(self):
|
|
||||||
return []
|
|
||||||
|
|
||||||
def get_global_names(self):
|
def get_global_names(self):
|
||||||
return self.children[1::2]
|
return self.children[1::2]
|
||||||
|
|
||||||
@@ -984,12 +982,9 @@ class ReturnStmt(KeywordStatement):
|
|||||||
|
|
||||||
|
|
||||||
class YieldExpr(PythonBaseNode):
|
class YieldExpr(PythonBaseNode):
|
||||||
|
type = 'yield_expr'
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
@property
|
|
||||||
def type(self):
|
|
||||||
return 'yield_expr'
|
|
||||||
|
|
||||||
|
|
||||||
def _defined_names(current):
|
def _defined_names(current):
|
||||||
"""
|
"""
|
||||||
@@ -1030,14 +1025,20 @@ class ExprStmt(PythonBaseNode, DocstringMixin):
|
|||||||
"""Returns the right-hand-side of the equals."""
|
"""Returns the right-hand-side of the equals."""
|
||||||
return self.children[-1]
|
return self.children[-1]
|
||||||
|
|
||||||
def first_operation(self):
|
def yield_operators(self):
|
||||||
"""
|
"""
|
||||||
Returns `+=`, `=`, etc or None if there is no operation.
|
Returns a generator of `+=`, `=`, etc. or None if there is no operation.
|
||||||
"""
|
"""
|
||||||
try:
|
first = self.children[1]
|
||||||
return self.children[1]
|
if first.type == 'annassign':
|
||||||
except IndexError:
|
if len(first.children) <= 2:
|
||||||
return None
|
return # No operator is available, it's just PEP 484.
|
||||||
|
|
||||||
|
first = first.children[2]
|
||||||
|
yield first
|
||||||
|
|
||||||
|
for operator in self.children[3::2]:
|
||||||
|
yield operator
|
||||||
|
|
||||||
|
|
||||||
class Param(PythonBaseNode):
|
class Param(PythonBaseNode):
|
||||||
@@ -1109,6 +1110,7 @@ class Param(PythonBaseNode):
|
|||||||
return search_ancestor(self, ('funcdef', 'lambda'))
|
return search_ancestor(self, ('funcdef', 'lambda'))
|
||||||
|
|
||||||
def get_description(self):
|
def get_description(self):
|
||||||
|
# TODO Remove?
|
||||||
children = self.children
|
children = self.children
|
||||||
if children[-1] == ',':
|
if children[-1] == ',':
|
||||||
children = children[:-1]
|
children = children[:-1]
|
||||||
|
|||||||
Reference in New Issue
Block a user