1
0
forked from VimPlug/jedi

improved param generator

This commit is contained in:
David Halter
2013-02-10 02:01:27 +01:00
parent 0008531a30
commit cd49126733
2 changed files with 25 additions and 10 deletions

View File

@@ -495,23 +495,38 @@ class Execution(Executable):
""" """
Create a param with the original scope (of varargs) as parent. Create a param with the original scope (of varargs) as parent.
""" """
# TODO remove array and param and just put the values of the \
# statement into the values of the param - it's as simple as that.
if isinstance(self.var_args, pr.Array): if isinstance(self.var_args, pr.Array):
parent = self.var_args.parent parent = self.var_args.parent
start_pos = self.var_args.start_pos start_pos = self.var_args.start_pos
else: else:
parent = self.base parent = self.base
start_pos = None start_pos = None
# create an Array (-> container for the statement)
arr = pr.Array(self.module, start_pos, pr.Array.NOARRAY, parent)
arr.values = values
arr.keys = keys
arr.type = array_type
new_param = copy.copy(param) new_param = copy.copy(param)
new_param.is_generated = True
if parent is not None: if parent is not None:
new_param.parent = parent new_param.parent = parent
new_param._commands = [arr]
new_param.is_generated = True if array_type is not None:
# create an Array (-> needed for *args/**kwargs tuples/dicts)
arr = pr.Array(self.module, start_pos, array_type, parent)
"""
for i, value in enumerate(values): # TODO delete?
try:
keys[i]
except IndexError:
pass
"""
arr.values = values
arr.keys = keys
arr.type = array_type
new_param._commands = [arr]
else:
new_param._commands = values
name = copy.copy(param.get_name()) name = copy.copy(param.get_name())
name.parent = new_param name.parent = new_param
return name return name

View File

@@ -24,7 +24,7 @@ import re
import tokenize import tokenize
from _compatibility import next, literal_eval, cleandoc, Python3Method, \ from _compatibility import next, literal_eval, cleandoc, Python3Method, \
property property, unicode
import common import common
import debug import debug
@@ -711,7 +711,7 @@ class Statement(Simple):
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):
pieces = [c.get_code() if isinstance(c, Simple) else c pieces = [c.get_code() if isinstance(c, Base) else c
for c in command_list] for c in command_list]
if assignment is None: if assignment is None:
return ''.join(pieces) return ''.join(pieces)
@@ -763,7 +763,7 @@ class Statement(Simple):
it and make it nicer, that would be cool :-) it and make it nicer, that would be cool :-)
""" """
def is_assignment(tok): def is_assignment(tok):
return tok is not None and tok.endswith('=') \ return isinstance(tok, (str, unicode)) and tok.endswith('=') \
and not tok in ['>=', '<=', '==', '!='] and not tok in ['>=', '<=', '==', '!=']
def parse_array(token_iterator, array_type, start_pos, add_el=None): def parse_array(token_iterator, array_type, start_pos, add_el=None):