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