forked from VimPlug/jedi
Get lambdas mostly working.
This commit is contained in:
@@ -176,6 +176,8 @@ class Evaluator(object):
|
||||
elif isinstance(element, pr.Keyword):
|
||||
# For False/True/None
|
||||
return [compiled.builtin.get_by_name(element.value)]
|
||||
elif isinstance(element, pr.Lambda):
|
||||
return [er.LambdaWrapper(self, element)]
|
||||
elif element.type == 'power':
|
||||
types = self._eval_atom(element.children[0])
|
||||
for trailer in element.children[1:]:
|
||||
|
||||
@@ -74,9 +74,12 @@ class NameFinder(object):
|
||||
except KeyError:
|
||||
return []
|
||||
|
||||
if isinstance(scope, pr.CompFor):
|
||||
if isinstance(scope, (pr.CompFor, pr.Lambda)):
|
||||
return names
|
||||
names = pr.filter_after_position(names, position)
|
||||
|
||||
if not (isinstance(scope, er.FunctionExecution)
|
||||
and isinstance(scope.base, er.LambdaWrapper)):
|
||||
names = pr.filter_after_position(names, position)
|
||||
names = [name for name in names if name.is_definition()]
|
||||
|
||||
# Only the names defined in the last position are valid definitions.
|
||||
@@ -539,6 +542,7 @@ def get_names_of_scope(evaluator, scope, position=None, star_search=True, includ
|
||||
if isinstance(scope, pr.SubModule) and scope.parent or not scope.is_scope():
|
||||
scope = scope.parent
|
||||
continue
|
||||
|
||||
# `pr.Class` is used, because the parent is never `Class`.
|
||||
# Ignore the Flows, because the classes and functions care for that.
|
||||
# InstanceElement of Class is ignored, if it is not the start scope.
|
||||
|
||||
@@ -76,7 +76,7 @@ class Executed(pr.Base):
|
||||
return True
|
||||
|
||||
def get_parent_until(self, *args, **kwargs):
|
||||
return self.base.get_parent_until(*args, **kwargs)
|
||||
return pr.Base.get_parent_until(self, *args, **kwargs)
|
||||
|
||||
@common.safe_property
|
||||
def parent(self):
|
||||
@@ -512,7 +512,7 @@ class Function(use_metaclass(CachedMetaClass, Wrapper)):
|
||||
|
||||
debug.dbg('decorator end %s', f)
|
||||
|
||||
if isinstance(f, pr.Function):
|
||||
if isinstance(f, (pr.Function, pr.Lambda)):
|
||||
return self
|
||||
return f
|
||||
|
||||
@@ -542,6 +542,10 @@ class Function(use_metaclass(CachedMetaClass, Wrapper)):
|
||||
return "<e%s of %s%s>" % (type(self).__name__, self.base_func, dec)
|
||||
|
||||
|
||||
class LambdaWrapper(Function):
|
||||
pass
|
||||
|
||||
|
||||
class LazyDict(object):
|
||||
def __init__(self, old_dct, copy_func):
|
||||
self._copy_func = copy_func
|
||||
@@ -588,6 +592,9 @@ class FunctionExecution(Executed):
|
||||
# inserted params, not in the actual execution of the function.
|
||||
return []
|
||||
|
||||
if isinstance(func, LambdaWrapper):
|
||||
return self._evaluator.eval_element(self.children[-1])
|
||||
|
||||
if check_yields:
|
||||
types = []
|
||||
returns = self.yields
|
||||
|
||||
Reference in New Issue
Block a user