-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Previously this code
{
"dictP" : {"A" : 1, "B" : 2},
"newparam" : ${dictP}['${dictP}']
}
caused newparam to have string value '{'A': 1, 'B': 2}['{'A': 1, 'B': 2}']'.
With latest changes of the JsonPreprocessor this changes to newparam having dictionary value {'A': 1, 'B': 2}.
Both is wrong.
The meaning of ${dictP}['${dictP}'] is: A dictionary is converted to a string; the result is used as key of a dictionary.
Is this possible? Yes. Does this makes sense? Not really.
I checked in pure Python:
dictparam = {'A': 1, 'B': 2}
str_dictparam = str(dictparam)
dictparam2 = {}
dictparam2["{'A': 1, 'B': 2}"] = 123
value = dictparam2[str_dictparam]
print(f"value = {value}")
Outcome
value = 123
Conclusion: An expression like this "{'A': 1, 'B': 2}" can be used as key.
I am not sure if we shall allow this. It's strange. But keys can be of type str. This is allowed. And if a user decides to
convert a dictionary to a string and use this string as key, like in ['${dictP}'], then it is like it is.
It has to be possible to take a key name out of a dictionary and use this key as key for another dictionary. Therefore we cannot suppress using composite data types inside square brackets.
Example:
"dictP1" : {"A" : 1 , "B" : 2},
"dictP2" : {"1" : "C", "2" : "D"},
"newparam" : ${dictP2}['${dictP1}['A']']
The result is correct:
'newparam': 'C'
Finally this is my proposal: We follow the Python philosophy. Users get a high degree of freedom, but must be aware of what they do.
Coming back now to the first example from above:
{
"dictP" : {"A" : 1, "B" : 2},
"newparam" : ${dictP}['${dictP}']
}
This code has to cause a "key error". Because of a key with name '{"A" : 1, "B" : 2}' does not exist inside dictP.
Metadata
Metadata
Assignees
Labels
Projects
Status