fixed mostly wrong lambda tests (and a few lambda improvements as well)

This commit is contained in:
David Halter
2012-12-23 15:52:49 +01:00
parent c7fd196850
commit 716d2362fd
3 changed files with 16 additions and 7 deletions

View File

@@ -829,7 +829,7 @@ class Array(use_metaclass(cache.CachedMetaClass, parsing.Base)):
return builtin.Builtin.scope
def __getattr__(self, name):
if name not in ['type', 'start_pos']:
if name not in ['type', 'start_pos', 'get_only_subelement']:
raise AttributeError('Strange access: %s.' % name)
return getattr(self._array, name)
@@ -1373,9 +1373,11 @@ def follow_call_list(call_list):
# comprehensions
result += follow_statement(stmt)
else:
if isinstance(call, (parsing.Lambda)):
result.append(Function(call))
# With things like params, these can also be functions...
if isinstance(call, (parsing.Lambda, Function, Class,
Instance, dynamic.ArrayInstance)):
elif isinstance(call, (Function, Class, Instance,
dynamic.ArrayInstance)):
result.append(call)
# The string tokens are just operations (+, -, etc.)
elif not isinstance(call, (str, unicode)):

View File

@@ -445,6 +445,10 @@ class Lambda(Function):
string = "lambda %s:" % params
return string + super(Function, self).get_code(indention=indention)
def __repr__(self):
return "<%s @%s (%s-%s)>" % (type(self).__name__, self.start_pos[0],
self.start_pos[1], self.end_pos[1])
class Flow(Scope):
"""
@@ -1551,6 +1555,7 @@ class PyFuzzyParser(object):
if ret is not None:
ret.parent = lambd
lambd.returns.append(ret)
lambd.end_pos = ret.end_pos
lambd.parent = self.scope
tok_list[-1] = lambd
continue

View File

@@ -373,11 +373,11 @@ a(0)
arg_l = lambda x, y: y, x
#? float()
argl[0]('', 1.0)
arg_l[0]('', 1.0)
#? list()
arg_l[1]
arg_l = lambda x, y: y, x
arg_l = lambda x, y: (y, x)
args = 1,""
result = arg_l(*args)
#? tuple()
@@ -395,9 +395,11 @@ with_lambda(arg_l, 1.0)[1]
#? float()
with_lambda(arg_l, 1.0)[0]
#? float()
with_lambda(arg_l, x=1.0)[0]
with_lambda(arg_l, y=1.0)[0]
#? int()
with_lambda(lambda x: x)
#? float()
with_lambda(lambda x: x, x=1.0)[0]
with_lambda(lambda x, y: y, y=1.0)
arg_func = lambda *args, **kwargs: args[0], kwargs['a']
#? int()