Commit d7cb9cd5 authored by sparonuz's avatar sparonuz
Browse files

Fix for keyword argument which have the same name of the actual argument #127

parent 40dc8d9e
......@@ -302,7 +302,8 @@ def add_rpe_to_array_arguments(argument):
ret_val = ret_val[:-2] + "/)"
return ret_val
def replace_variable_exact_match(piece_to_replace, replacement, str):
def replace_variable_exact_match(piece_to_replace, replacement, string):
# In case string does start with a char we'll add the \b to indicate a word border
if re.match("\w", piece_to_replace.strip()[0]):
piece_to_replace = "\\b" + piece_to_replace.strip()
......@@ -322,12 +323,12 @@ def replace_variable_exact_match(piece_to_replace, replacement, str):
piece_to_replace = piece_to_replace + "\\b(?!%val)"
piece_to_replace = piece_to_replace + "\\b(?! *\()"
# Before performing the substitution remove strings to avoid substitution inside them
mask = BasicFunctions.literal_mask(str)
mask = BasicFunctions.literal_mask(string)
literal_part = []
n_of_literal = -1
# Transforms the string in a list of char (strings are immutable and cannot be modified)
str = list(itertools.chain.from_iterable([list(piece) for piece in list(str)]))
string = list(itertools.chain.from_iterable([list(piece) for piece in list(string)]))
for index, i in enumerate(mask):
if i:
# A new literal is beginning, add a list to store its value
......@@ -335,19 +336,33 @@ def replace_variable_exact_match(piece_to_replace, replacement, str):
n_of_literal += 1
literal_part.append([])
# The char is stored for late substitution
literal_part[n_of_literal].append(str[index])
literal_part[n_of_literal].append(string[index])
# The char is overwrite with a placeholder
str[index] = "#"
string[index] = "#"
# Reconvert the list to string and substitute the fix
str = "".join(str)
str = re.sub(piece_to_replace, replacement, str)
string = "".join(string)
# Check the argument is passed with the same name as the keyword
keyword = re.search(r'(%s\s*=\s*)%s' % (piece_to_replace, piece_to_replace), string, re.I)
if keyword:
string = list(itertools.chain.from_iterable([list(piece) for piece in list(string)]))
# avoid casting the keyword
len_keyword = len(keyword.group(1))
n_of_literal += 1
literal_part.append([])
for i in range(keyword.start(), keyword.start()+len_keyword):
literal_part[n_of_literal].append(string[i])
string[i] = "#"
string = "".join(string)
string = re.sub(piece_to_replace, replacement, string)
# Substitutes one at a time the placeholder for the char
for index, substitution in enumerate(literal_part):
str = re.sub("#+", "".join(literal_part[index]), str, 1)
string = re.sub("#+", "".join(literal_part[index]), string, 1)
return str
return string
def _remove_keywords(arguments):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment