forked from VimPlug/jedi
Fixing lambdas.
This commit is contained in:
@@ -270,8 +270,8 @@ class Evaluator(object):
|
||||
if element.value in ('False', 'True', 'None'):
|
||||
types.add(compiled.builtin_from_name(self, element.value))
|
||||
# else: print e.g. could be evaluated like this in Python 2.7
|
||||
elif element.isinstance(tree.Lambda):
|
||||
types = set([er.LambdaWrapper(self, element)])
|
||||
elif isinstance(element, tree.Lambda):
|
||||
types = set([er.LambdaWrapper(self, context, element)])
|
||||
elif element.isinstance(er.LambdaWrapper):
|
||||
types = set([element]) # TODO this is no real evaluation.
|
||||
elif element.type == 'expr_stmt':
|
||||
|
||||
@@ -104,21 +104,22 @@ def _search_function_executions(evaluator, module_context, funcdef):
|
||||
from jedi.evaluate import representation as er
|
||||
|
||||
def get_possible_nodes(module_context, func_name):
|
||||
try:
|
||||
names = module_context.module_node.used_names[func_name]
|
||||
except KeyError:
|
||||
return
|
||||
if not isinstance(module_context, er.ModuleContext):
|
||||
return
|
||||
try:
|
||||
names = module_context.module_node.used_names[func_name]
|
||||
except KeyError:
|
||||
return
|
||||
|
||||
for name in names:
|
||||
bracket = name.get_next_leaf()
|
||||
trailer = bracket.parent
|
||||
if trailer.type == 'trailer' and bracket == '(':
|
||||
yield name, trailer
|
||||
for name in names:
|
||||
bracket = name.get_next_leaf()
|
||||
trailer = bracket.parent
|
||||
if trailer.type == 'trailer' and bracket == '(':
|
||||
yield name, trailer
|
||||
|
||||
func_name = unicode(funcdef.name)
|
||||
compare_node = funcdef
|
||||
if func_name == '__init__':
|
||||
raise NotImplementedError
|
||||
cls = funcdef.get_parent_scope()
|
||||
if isinstance(cls, tree.Class):
|
||||
func_name = unicode(cls.name)
|
||||
|
||||
@@ -64,6 +64,7 @@ def deep_ast_copy(obj, parent=None, new_elements=None):
|
||||
|
||||
if parent is not None:
|
||||
new_obj.parent = parent
|
||||
raise NotImplementedError
|
||||
return new_obj
|
||||
|
||||
|
||||
@@ -94,12 +95,14 @@ def call_of_leaf(leaf, cut_own_trailer=False):
|
||||
|
||||
power = trailer.parent
|
||||
index = power.children.index(trailer)
|
||||
power = deep_ast_copy(power)
|
||||
if cut_own_trailer:
|
||||
cut = index
|
||||
else:
|
||||
cut = index + 1
|
||||
power.children[cut:] = []
|
||||
|
||||
new_power = copy.copy(power)
|
||||
new_power.children = list(new_power.children)
|
||||
new_power.children[cut:] = []
|
||||
|
||||
if power.type == 'error_node':
|
||||
start = index
|
||||
|
||||
@@ -375,7 +375,12 @@ class ParamArguments(object):
|
||||
self._class_context,
|
||||
self._funcdef
|
||||
)
|
||||
is_first = True
|
||||
for p in params:
|
||||
# TODO Yeah, here at last, the class seems to be really wrong.
|
||||
if is_first:
|
||||
is_first = False
|
||||
continue
|
||||
yield None, self.LazyParamContext(p)
|
||||
|
||||
|
||||
|
||||
@@ -209,6 +209,7 @@ class Comprehension(AbstractSequence):
|
||||
# InstanceElement anyway, I don't care.
|
||||
node = node.var
|
||||
last_comp = list(comp_for.get_comp_fors())[-1]
|
||||
raise NotImplementedError('should not need to copy...')
|
||||
return helpers.deep_ast_copy(node, parent=last_comp)
|
||||
|
||||
def _nested(self, comp_fors):
|
||||
|
||||
@@ -598,8 +598,7 @@ class FunctionContext(use_metaclass(CachedMetaClass, context.TreeContext, Wrappe
|
||||
|
||||
|
||||
class LambdaWrapper(FunctionContext):
|
||||
def get_decorated_func(self):
|
||||
return self
|
||||
pass
|
||||
|
||||
|
||||
class FunctionExecutionContext(Executed):
|
||||
@@ -638,8 +637,8 @@ class FunctionExecutionContext(Executed):
|
||||
@recursion.execution_recursion_decorator
|
||||
def get_return_values(self, check_yields=False):
|
||||
funcdef = self.funcdef
|
||||
if funcdef.type in ('lambdef', 'lambdef_nocond'):
|
||||
return self.evaluator.eval_element(self.children[-1])
|
||||
if isinstance(funcdef, tree.Lambda):
|
||||
return self.evaluator.eval_element(self, funcdef.children[-1])
|
||||
|
||||
"""
|
||||
if func.listeners:
|
||||
@@ -821,7 +820,7 @@ class ModuleContext(use_metaclass(CachedMetaClass, context.TreeContext, Wrapper)
|
||||
name = i.star_import_name()
|
||||
new = imports.ImportWrapper(self, name).follow()
|
||||
for module in new:
|
||||
if isinstance(module, tree.Module):
|
||||
if isinstance(module, ModuleContext):
|
||||
modules += module.star_imports()
|
||||
modules += new
|
||||
return modules
|
||||
|
||||
Reference in New Issue
Block a user