forked from VimPlug/jedi
Make the some names more concise in the parser tree.
This commit is contained in:
@@ -81,6 +81,7 @@ from jedi.evaluate import pep0484
|
||||
from jedi.evaluate.filters import TreeNameDefinition, ParamName
|
||||
from jedi.evaluate.instance import AnonymousInstance, BoundMethod
|
||||
from jedi.evaluate.context import ContextualizedName, ContextualizedNode
|
||||
from jedi import parser_utils
|
||||
|
||||
|
||||
class Evaluator(object):
|
||||
@@ -165,11 +166,11 @@ class Evaluator(object):
|
||||
|
||||
for_stmt = tree.search_ancestor(stmt, 'for_stmt')
|
||||
if for_stmt is not None and for_stmt.type == 'for_stmt' and types \
|
||||
and for_stmt.defines_one_name():
|
||||
and parser_utils.for_stmt_defines_one_name(for_stmt):
|
||||
# Iterate through result and add the values, that's possible
|
||||
# only in for loops without clutter, because they are
|
||||
# predictable. Also only do it, if the variable is not a tuple.
|
||||
node = for_stmt.get_input_node()
|
||||
node = for_stmt.get_testlist()
|
||||
cn = ContextualizedNode(context, node)
|
||||
ordered = list(iterable.py__iter__(self, cn.infer(), cn))
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ def _check_for_exception_catch(node_context, jedi_name, exception, payload=None)
|
||||
and not (branch_type.start_pos < jedi_name.start_pos <= suite.end_pos):
|
||||
return False
|
||||
|
||||
for node in obj.except_clauses():
|
||||
for node in obj.get_except_clauses():
|
||||
if node is None:
|
||||
return True # An exception block that catches everything.
|
||||
else:
|
||||
|
||||
@@ -62,6 +62,7 @@ from jedi.evaluate.filters import ParserTreeFilter, FunctionExecutionFilter, \
|
||||
from jedi.evaluate.dynamic import search_params
|
||||
from jedi.evaluate import context
|
||||
from jedi.evaluate.context import ContextualizedNode
|
||||
from jedi import parser_utils
|
||||
|
||||
|
||||
def apply_py__get__(context, base_context):
|
||||
@@ -353,7 +354,7 @@ class FunctionExecutionContext(context.TreeContext):
|
||||
if parent.type == 'suite':
|
||||
parent = parent.parent
|
||||
if for_stmt.type == 'for_stmt' and parent == self.tree_node \
|
||||
and for_stmt.defines_one_name(): # Simplicity for now.
|
||||
and parser_utils.for_stmt_defines_one_name(for_stmt): # Simplicity for now.
|
||||
if for_stmt == last_for_stmt:
|
||||
yields_order[-1][1].append(yield_)
|
||||
else:
|
||||
@@ -375,7 +376,7 @@ class FunctionExecutionContext(context.TreeContext):
|
||||
for result in self._eval_yield(yield_):
|
||||
yield result
|
||||
else:
|
||||
input_node = for_stmt.get_input_node()
|
||||
input_node = for_stmt.get_testlist()
|
||||
cn = ContextualizedNode(self, input_node)
|
||||
ordered = iterable.py__iter__(evaluator, cn.infer(), cn)
|
||||
ordered = list(ordered)
|
||||
|
||||
@@ -745,32 +745,24 @@ class ForStmt(Flow):
|
||||
type = 'for_stmt'
|
||||
__slots__ = ()
|
||||
|
||||
def get_input_node(self):
|
||||
def get_testlist(self):
|
||||
"""
|
||||
Returns the input node ``y`` from: ``for x in y:``.
|
||||
"""
|
||||
return self.children[3]
|
||||
|
||||
def defines_one_name(self):
|
||||
"""
|
||||
Returns True if only one name is returned: ``for x in y``.
|
||||
Returns False if the for loop is more complicated: ``for x, z in y``.
|
||||
|
||||
:returns: bool
|
||||
"""
|
||||
return self.children[1].type == 'name'
|
||||
|
||||
|
||||
class TryStmt(Flow):
|
||||
type = 'try_stmt'
|
||||
__slots__ = ()
|
||||
|
||||
def except_clauses(self):
|
||||
def get_except_clauses(self):
|
||||
"""
|
||||
Returns the ``test`` nodes found in ``except_clause`` nodes.
|
||||
Returns ``[None]`` for except clauses without an exception given.
|
||||
"""
|
||||
for node in self.children:
|
||||
# TODO this is not correct. We're not returning an except clause.
|
||||
if node.type == 'except_clause':
|
||||
yield node.children[1]
|
||||
elif node == 'except':
|
||||
@@ -790,6 +782,7 @@ class WithStmt(Flow):
|
||||
return names
|
||||
|
||||
def get_context_manager_from_name(self, name):
|
||||
# TODO Replace context_manager with test?
|
||||
node = name.parent
|
||||
if node.type != 'with_item':
|
||||
raise ValueError('The name is not actually part of a with statement.')
|
||||
|
||||
@@ -58,3 +58,13 @@ def get_comp_fors(comp_for):
|
||||
elif not last.type == 'comp_if':
|
||||
break
|
||||
last = last.children[-1]
|
||||
|
||||
|
||||
def for_stmt_defines_one_name(for_stmt):
|
||||
"""
|
||||
Returns True if only one name is returned: ``for x in y``.
|
||||
Returns False if the for loop is more complicated: ``for x, z in y``.
|
||||
|
||||
:returns: bool
|
||||
"""
|
||||
return for_stmt.children[1].type == 'name'
|
||||
|
||||
Reference in New Issue
Block a user