forked from VimPlug/jedi
Lambdas are own namespaces and deserve their own used_names dictionary in the parser.
This commit is contained in:
@@ -158,6 +158,8 @@ class Parser(object):
|
|||||||
# returned by convert multiple times.
|
# returned by convert multiple times.
|
||||||
if symbol == 'global_stmt':
|
if symbol == 'global_stmt':
|
||||||
self.global_names += new_node.get_defined_names()
|
self.global_names += new_node.get_defined_names()
|
||||||
|
elif isinstance(new_node, pt.Lambda):
|
||||||
|
new_node.names_dict = self.scope_names_stack.pop()
|
||||||
elif isinstance(new_node, (pt.ClassOrFunc, pt.Module)) \
|
elif isinstance(new_node, (pt.ClassOrFunc, pt.Module)) \
|
||||||
and symbol in ('funcdef', 'classdef', 'file_input'):
|
and symbol in ('funcdef', 'classdef', 'file_input'):
|
||||||
# scope_name_stack handling
|
# scope_name_stack handling
|
||||||
@@ -180,7 +182,7 @@ class Parser(object):
|
|||||||
#print('leaf', value, pytree.type_repr(type))
|
#print('leaf', value, pytree.type_repr(type))
|
||||||
if type == tokenize.NAME:
|
if type == tokenize.NAME:
|
||||||
if value in grammar.keywords:
|
if value in grammar.keywords:
|
||||||
if value in ('def', 'class'):
|
if value in ('def', 'class', 'lambda'):
|
||||||
self.scope_names_stack.append({})
|
self.scope_names_stack.append({})
|
||||||
|
|
||||||
return pt.Keyword(value, start_pos, prefix)
|
return pt.Keyword(value, start_pos, prefix)
|
||||||
@@ -265,7 +267,7 @@ class Parser(object):
|
|||||||
if found:
|
if found:
|
||||||
symbol = grammar.number2symbol[typ]
|
symbol = grammar.number2symbol[typ]
|
||||||
failed_stack.append((symbol, nodes))
|
failed_stack.append((symbol, nodes))
|
||||||
if nodes and nodes[0] in ('def', 'class'):
|
if nodes and nodes[0] in ('def', 'class', 'lambda'):
|
||||||
self.scope_names_stack.pop()
|
self.scope_names_stack.pop()
|
||||||
if failed_stack:
|
if failed_stack:
|
||||||
err = ErrorStatement(failed_stack, value, start_pos)
|
err = ErrorStatement(failed_stack, value, start_pos)
|
||||||
|
|||||||
@@ -880,8 +880,6 @@ class Lambda(Function):
|
|||||||
self.listeners = set() # not used here, but in evaluation.
|
self.listeners = set() # not used here, but in evaluation.
|
||||||
lst = self.children[1:-2] # After `def foo`
|
lst = self.children[1:-2] # After `def foo`
|
||||||
self.params = _create_params(self, lst)
|
self.params = _create_params(self, lst)
|
||||||
self.names_dict = dict((str(param.name), [param.name])
|
|
||||||
for param in self.params)
|
|
||||||
|
|
||||||
def is_generator(self):
|
def is_generator(self):
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user