preserve original type of the variable if not part of a composite expression
@@ -23,6 +23,11 @@ class ConstVariableEvaluation(BaseVariableEvaluation):
def _extract_context_path(definition_path):
return os.path.split("/".join(re.findall(TF_DEFINITIONS_STRIP_WORDS, definition_path)))
+ @staticmethod
+ def _is_variable_only_expression(assignment_regex, entry_expression):
+ exact_assignment_regex = r'^' + assignment_regex + r'$'
+ return len(re.findall(exact_assignment_regex, entry_expression)) > 0
+
def _locate_assignments(self, folder, var_name):
var_assignments_paths = {}
assignment_regex = self._generate_var_evaluation_regex(var_name)
@@ -44,6 +49,7 @@ class ConstVariableEvaluation(BaseVariableEvaluation):
def _assign_definition_value(self, var_name, var_value, var_assignments):
assignment_regex = self._generate_var_evaluation_regex(var_name)
var_file = var_assignments['var_file']
+ var_value_string = str(var_value)
for (assignment_file, assignments) in var_assignments['definitions'].items():
# Save evaluation information in context
for assignment_obj in assignments:
@@ -58,12 +64,16 @@ class ConstVariableEvaluation(BaseVariableEvaluation):
dpath.new(self.definitions_context[assignment_file],
f'evaluations/{var_name}/definitions',
assignments)
- evaluated_value = str(var_value)
- evaluated_definition = re.sub(assignment_regex, evaluated_value, entry_expression)
+ if self._is_variable_only_expression(assignment_regex, entry_expression):
+ # Preserve the original type of the variable if not part of a composite expression
+ evaluated_definition = var_value
+ else:
+ evaluated_definition = re.sub(assignment_regex, var_value_string, entry_expression)
+
dpath.set(self.tf_definitions[assignment_file], definition_path, evaluated_definition)
self.logger.debug(
f'Evaluated definition {definition_name} in file {assignment_file}: default value of variable {var_file}: '
- f'{var_name} to "{evaluated_value}"')
+ f'{var_name} to "{var_value_string}"')
def _evaluate_folder_variables(self, folder):
assignment_files = dpath.search(self.definitions_context, f'**.assignments', separator='.')
