Commit 79d2a8ed authored by Jiahang Chen's avatar Jiahang Chen
Browse files

fix python built-in var conflict

parent b860b27a
Pipeline #458960 passed with stages
in 51 seconds
""" This module implements a factory for managing and creating Digital Twins according to Forest Modeling Language 4.0.""" """ This module implements a factory for managing and creating Digital Twins according to Forest Modeling Language 4.0."""
from ml.app_logger import APP_LOGGER from ml.app_logger import APP_LOGGER
from ml.tools import remove_namespace from ml.tools import remove_namespace, check_var_conflict
from ml.ditto_feature import ditto_feature from ml.ditto_feature import ditto_feature
from ml.thing import Thing from ml.thing import Thing
from ml.ml40.roles.servives.service import Service from ml.ml40.roles.servives.service import Service
...@@ -308,7 +308,7 @@ def build_feature(feature): ...@@ -308,7 +308,7 @@ def build_feature(feature):
elif key == "subFeatures": elif key == "subFeatures":
build_sub_features(feature_instance, feature) build_sub_features(feature_instance, feature)
else: else:
setattr(feature_instance, key, feature[key]) setattr(feature_instance, check_var_conflict(key), feature[key])
return feature_instance return feature_instance
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
import os import os
IDENTITY_PROVIDER_URL = "https://idp.s3i.vswf.dev/" IDENTITY_PROVIDER_URL = "https://idp.s3i.vswf.dev/"
BUILT_IN = ["from", "str", "dict", "list", "bool", "float", "int", "tuple",
"def", "return", "for", "if", "class", "try", "except"]
class BColors: class BColors:
"""colors for the console log""" """colors for the console log"""
...@@ -156,3 +157,16 @@ def remove_namespace(input_str): ...@@ -156,3 +157,16 @@ def remove_namespace(input_str):
""" """
return input_str.replace("fml40::", "").replace("ml40::", "") return input_str.replace("fml40::", "").replace("ml40::", "")
def check_var_conflict(var):
"""
check if the input is built-in variable
:param var: python var
:return: modified variable, if the input is a input variable.
"""
if var in BUILT_IN:
return "_{}".format(var)
else:
return var
\ No newline at end of file
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