forked from VimPlug/jedi
use as_names as a way to inject 'set_vars' to statements
This commit is contained in:
@@ -344,6 +344,7 @@ class Parser(object):
|
|||||||
breaks |= set(added_breaks)
|
breaks |= set(added_breaks)
|
||||||
|
|
||||||
tok_list = []
|
tok_list = []
|
||||||
|
as_names = []
|
||||||
while not (tok in always_break
|
while not (tok in always_break
|
||||||
or tok in not_first_break and not tok_list
|
or tok in not_first_break and not tok_list
|
||||||
or tok in breaks and level <= 0):
|
or tok in breaks and level <= 0):
|
||||||
@@ -356,6 +357,7 @@ class Parser(object):
|
|||||||
n, token_type, tok = self._parse_dot_name(self._current)
|
n, token_type, tok = self._parse_dot_name(self._current)
|
||||||
if n:
|
if n:
|
||||||
set_vars.append(n)
|
set_vars.append(n)
|
||||||
|
as_names.append(n)
|
||||||
tok_list.append(n)
|
tok_list.append(n)
|
||||||
continue
|
continue
|
||||||
elif tok in ['lambda', 'for', 'in']:
|
elif tok in ['lambda', 'for', 'in']:
|
||||||
@@ -394,7 +396,7 @@ class Parser(object):
|
|||||||
return None, tok
|
return None, tok
|
||||||
else:
|
else:
|
||||||
stmt = stmt_class(self.module, set_vars, used_vars, tok_list,
|
stmt = stmt_class(self.module, set_vars, used_vars, tok_list,
|
||||||
first_pos, self.end_pos)
|
first_pos, self.end_pos, as_names=as_names)
|
||||||
|
|
||||||
stmt.parent = self.top_module
|
stmt.parent = self.top_module
|
||||||
self._check_user_stmt(stmt)
|
self._check_user_stmt(stmt)
|
||||||
@@ -597,13 +599,13 @@ class Parser(object):
|
|||||||
and tok not in [':', '\n']:
|
and tok not in [':', '\n']:
|
||||||
statement, tok = \
|
statement, tok = \
|
||||||
self._parse_statement(added_breaks=added_breaks)
|
self._parse_statement(added_breaks=added_breaks)
|
||||||
if command == 'except' and tok in added_breaks:
|
if command == 'except' and tok == ',':
|
||||||
# the except statement defines a var
|
# the except statement defines a var
|
||||||
# this is only true for python 2
|
# this is only true for python 2
|
||||||
n, token_type, tok = self._parse_dot_name()
|
n, token_type, tok = self._parse_dot_name()
|
||||||
if n:
|
if n:
|
||||||
n.parent = statement
|
n.parent = statement
|
||||||
statement.set_vars.append(n)
|
statement.as_names.append(n)
|
||||||
if statement:
|
if statement:
|
||||||
inputs.append(statement)
|
inputs.append(statement)
|
||||||
first = False
|
first = False
|
||||||
|
|||||||
@@ -758,11 +758,11 @@ class Statement(Simple):
|
|||||||
:param start_pos: Position (line, column) of the Statement.
|
:param start_pos: Position (line, column) of the Statement.
|
||||||
"""
|
"""
|
||||||
__slots__ = ('token_list', 'used_vars',
|
__slots__ = ('token_list', 'used_vars',
|
||||||
'_set_vars', '_commands', '_assignment_details',
|
'_set_vars', 'as_names', '_commands', '_assignment_details',
|
||||||
'docstr')
|
'docstr')
|
||||||
|
|
||||||
def __init__(self, module, set_vars, used_vars, token_list,
|
def __init__(self, module, set_vars, used_vars, token_list,
|
||||||
start_pos, end_pos, parent=None, set_name_parents=True):
|
start_pos, end_pos, parent=None, as_names=(), set_name_parents=True):
|
||||||
super(Statement, self).__init__(module, start_pos, end_pos)
|
super(Statement, self).__init__(module, start_pos, end_pos)
|
||||||
self.used_vars = used_vars
|
self.used_vars = used_vars
|
||||||
self.token_list = token_list
|
self.token_list = token_list
|
||||||
@@ -770,9 +770,12 @@ class Statement(Simple):
|
|||||||
for t in token_list:
|
for t in token_list:
|
||||||
if isinstance(t, Name):
|
if isinstance(t, Name):
|
||||||
t.parent = self.use_as_parent
|
t.parent = self.use_as_parent
|
||||||
|
for n in as_names:
|
||||||
|
n.parent = self.use_as_parent
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.docstr = ''
|
self.docstr = ''
|
||||||
self._set_vars = None
|
self._set_vars = None
|
||||||
|
self.as_names = list(as_names)
|
||||||
|
|
||||||
# cache
|
# cache
|
||||||
self._commands = None
|
self._commands = None
|
||||||
@@ -810,7 +813,7 @@ class Statement(Simple):
|
|||||||
for calls, operation in self.assignment_details:
|
for calls, operation in self.assignment_details:
|
||||||
search_calls(calls)
|
search_calls(calls)
|
||||||
self._set_vars = _set_vars
|
self._set_vars = _set_vars
|
||||||
return self._set_vars
|
return self._set_vars + self.as_names
|
||||||
|
|
||||||
def get_code(self, new_line=True):
|
def get_code(self, new_line=True):
|
||||||
def assemble(command_list, assignment=None):
|
def assemble(command_list, assignment=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user