Open HolQue opened 3 weeks ago
Similar issue with:
"newparam" : ${listP}['${listP}']
Hi @namsonx , @HolQue , expectation is:
if we have a composite type as result inside quotes, then we raise an error message
e.g.
{ "dictP" : {"A" : 1, "B" : 2}, "newparam" : ${dictP}['${dictP}'] }
What is allowed if the result inside the quotes is a simple data type.
e.g.
"dictP1" : {"A" : 1 , "B" : 2}, "dictP2" : {"1" : "C", "2" : "D"}, "newparam" : ${dictP2}['${dictP1}['A']']
This deviates from the python behavior. The assumption is that we hand-write the JSONP files, therefore it is not meaningful to allow stringified data-structures as key-name. This is valid on both, left and right side as well as standard- and dotdict notation.
Thank you, Thomas
Previously this code
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:
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:
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:
This code has to cause a "key error". Because of a key with name
'{"A" : 1, "B" : 2}'
does not exist insidedictP
.