lambda can be used as a default param in function, which means there have been slight changes to the parser to allow that (comma in a function definitions doesn't always mean new param), fixes #379

This commit is contained in:
Dave Halter
2014-03-11 12:24:36 +01:00
parent 18a012509f
commit cd7774f25f
2 changed files with 7 additions and 2 deletions

View File

@@ -311,9 +311,11 @@ class Parser(object):
tok_list = []
as_names = []
in_lambda_param = False
while not (tok.string in always_break
or tok.string in not_first_break and not tok_list
or tok.string in breaks and level <= 0):
or tok.string in breaks and level <= 0
and not (in_lambda_param and tok.string in ',:')):
try:
# print 'parse_stmt', tok, tokenize.tok_name[token_type]
is_kw = tok.string in OPERATOR_KEYWORDS
@@ -333,6 +335,9 @@ class Parser(object):
continue
elif tok.string == 'lambda':
breaks.discard(':')
in_lambda_param = True
elif in_lambda_param and tok.string == ':':
in_lambda_param = False
elif tok.type == tokenize.NAME and not is_kw:
n, tok = self._parse_dot_name(self._gen.current)
# removed last entry, because we add Name

View File

@@ -65,7 +65,7 @@ C().a()
# lambda param (#379)
# -----------------
class Test(object):
def __init__(self, pred=lambda x, y: x):
def __init__(self, pred=lambda a, b: a):
self.a = 1
#? int()
self.a