mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
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:
@@ -311,9 +311,11 @@ class Parser(object):
|
|||||||
|
|
||||||
tok_list = []
|
tok_list = []
|
||||||
as_names = []
|
as_names = []
|
||||||
|
in_lambda_param = False
|
||||||
while not (tok.string in always_break
|
while not (tok.string in always_break
|
||||||
or tok.string in not_first_break and not tok_list
|
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:
|
try:
|
||||||
# print 'parse_stmt', tok, tokenize.tok_name[token_type]
|
# print 'parse_stmt', tok, tokenize.tok_name[token_type]
|
||||||
is_kw = tok.string in OPERATOR_KEYWORDS
|
is_kw = tok.string in OPERATOR_KEYWORDS
|
||||||
@@ -333,6 +335,9 @@ class Parser(object):
|
|||||||
continue
|
continue
|
||||||
elif tok.string == 'lambda':
|
elif tok.string == 'lambda':
|
||||||
breaks.discard(':')
|
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:
|
elif tok.type == tokenize.NAME and not is_kw:
|
||||||
n, tok = self._parse_dot_name(self._gen.current)
|
n, tok = self._parse_dot_name(self._gen.current)
|
||||||
# removed last entry, because we add Name
|
# removed last entry, because we add Name
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ C().a()
|
|||||||
# lambda param (#379)
|
# lambda param (#379)
|
||||||
# -----------------
|
# -----------------
|
||||||
class Test(object):
|
class Test(object):
|
||||||
def __init__(self, pred=lambda x, y: x):
|
def __init__(self, pred=lambda a, b: a):
|
||||||
self.a = 1
|
self.a = 1
|
||||||
#? int()
|
#? int()
|
||||||
self.a
|
self.a
|
||||||
|
|||||||
Reference in New Issue
Block a user