Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
KWH40
fml40-reference-implementation
Commits
79d2a8ed
Commit
79d2a8ed
authored
May 02, 2021
by
Jiahang Chen
Browse files
fix python built-in var conflict
parent
b860b27a
Pipeline
#458960
passed with stages
in 51 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ml/dt_factory.py
View file @
79d2a8ed
""" 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.tools
import
remove_namespace
from
ml.tools
import
remove_namespace
,
check_var_conflict
from
ml.ditto_feature
import
ditto_feature
from
ml.thing
import
Thing
from
ml.ml40.roles.servives.service
import
Service
...
...
@@ -308,7 +308,7 @@ def build_feature(feature):
elif
key
==
"subFeatures"
:
build_sub_features
(
feature_instance
,
feature
)
else
:
setattr
(
feature_instance
,
key
,
feature
[
key
])
setattr
(
feature_instance
,
check_var_conflict
(
key
)
,
feature
[
key
])
return
feature_instance
...
...
ml/tools.py
View file @
79d2a8ed
...
...
@@ -4,7 +4,8 @@
import
os
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
:
"""colors for the console log"""
...
...
@@ -156,3 +157,16 @@ def remove_namespace(input_str):
"""
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment