1
0
forked from VimPlug/jedi

Start making executions work.

This commit is contained in:
Dave Halter
2014-10-16 10:58:27 +02:00
parent 7b91050c85
commit 887949e23f
3 changed files with 36 additions and 5 deletions

View File

@@ -170,6 +170,7 @@ class Evaluator(object):
if trailer == '**': # has a power operation. if trailer == '**': # has a power operation.
raise NotImplementedError raise NotImplementedError
types = self.eval_trailer(types, trailer) types = self.eval_trailer(types, trailer)
return types
else: else:
raise NotImplementedError raise NotImplementedError
@@ -191,6 +192,8 @@ class Evaluator(object):
def eval_trailer(self, types, trailer): def eval_trailer(self, types, trailer):
trailer_op, node = trailer.children[:2] trailer_op, node = trailer.children[:2]
if node == ')': # `arglist` is optional.
node = None
new_types = [] new_types = []
for typ in types: for typ in types:
if trailer_op == '.': if trailer_op == '.':
@@ -202,15 +205,16 @@ class Evaluator(object):
return new_types return new_types
@debug.increase_indent @debug.increase_indent
def execute(self, obj, params=()): def execute(self, obj, arguments=()):
arguments = er.Arguments(self, arguments)
if obj.isinstance(er.Function): if obj.isinstance(er.Function):
obj = obj.get_decorated_func() obj = obj.get_decorated_func()
debug.dbg('execute: %s %s', obj, params) debug.dbg('execute: %s %s', obj, arguments)
try: try:
# Some stdlib functions like super(), namedtuple(), etc. have been # Some stdlib functions like super(), namedtuple(), etc. have been
# hard-coded in Jedi to support them. # hard-coded in Jedi to support them.
return stdlib.execute(self, obj, params) return stdlib.execute(self, obj, arguments)
except stdlib.NotInStdLib: except stdlib.NotInStdLib:
pass pass
@@ -220,7 +224,7 @@ class Evaluator(object):
debug.warning("no execution possible %s", obj) debug.warning("no execution possible %s", obj)
return [] return []
else: else:
types = func(self, params) types = func(self, arguments)
debug.dbg('execute result: %s in %s', types, obj) debug.dbg('execute result: %s in %s', types, obj)
return types return types

View File

@@ -335,6 +335,31 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
return "<%s of %s>" % (type(self).__name__, self.var) return "<%s of %s>" % (type(self).__name__, self.var)
class Arguments(object):
def __init__(self, evaluator, argument_node):
self._argument_node = argument_node
self._evaluator = evaluator
def _split(self):
iterator = iter(self._argument_node.children)
for child in iterator:
if child == ',':
continue
elif child in ('*', '**'):
yield len(child), next(iterator)
else:
yield 0, child
def kwargs(self):
return []
def args(self):
return []
def eval_args(self):
return [self._evaluator.eval_element(el) for stars, el in self._split()]
class Wrapper(pr.Base): class Wrapper(pr.Base):
def is_scope(self): def is_scope(self):
return True return True

View File

@@ -581,7 +581,9 @@ class SubModule(Scope, Module):
string = re.sub('\.[a-z]+-\d{2}[mud]{0,3}$', '', r.group(1)) string = re.sub('\.[a-z]+-\d{2}[mud]{0,3}$', '', r.group(1))
# Positions are not real, but a module starts at (1, 0) # Positions are not real, but a module starts at (1, 0)
p = (1, 0) p = (1, 0)
return Name(self, string, self.use_as_parent, p) name = Name(string, p)
name.parent = self
return name
@property @property
def has_explicit_absolute_import(self): def has_explicit_absolute_import(self):