-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot enter a plain integer into an attribute specified as type=str
#15
Comments
Hm. This is an interesting edge case, though I believe it is consistent with the standard. YAML is typed. For example, The excerpt of the error message from your comment is missing the start.
Comments:
|
I suppose my confusion lies at the fact that sometimes the data can be casted from one type to another using the
In that case, a float is cast into an integer. So the But in the case that I provided in my initial comment,
But instead, in my original example, the casting takes place and you get an error message that shows two values which look exactly the same. It does not make it clear that the error resulted because the casting cannot be performed in this particular case, and this is not obvious otherwise because sometimes the casting can be performed without error. Does that make sense? With my use case right now, I can get around this easily enough just by using quotes. I just wanted to report the confusing behavior. |
Yup.. that's a good point. I think I lean more toward being strict than lenient. YAML is nice because it is mostly human maintainable. I believe I originally added the cast for int -> float conversion, because humans don't care about decimals when the float is a round number, and writing So.... Now you've got me thinking. Is the right approach to create a yamlize.FloatLike object? I think we might be able to get rid of the cast validation which I believe would help reduce the inconsistency which you've pointed out. Are you working with ARMI friends? I'd have to bump the version for sure. |
I think what you propose could be a good approach, but I'm not exactly clear on what you were thinking. My interpretation is that this would allow a user to do something like this without ambiguity:
If that is indeed what you were thinking, perhaps also a
I might be misunderstanding what you are suggesting, though, so please let me know if my interpretation is off. |
But now that I type that out... I doubt that is what you were thinking because it moves further away from the underlying assumptions of YAML (i.e. that |
Um. I think I like the StrLike implementation you're describing. Off hand, I'm not sure how to do it. It would be pretty confusing for another YAML interpreter to read, but I guess that's not our problem.
The
No. Definitely want to keep that. It's been so long, but I'm pretty sure this is with regard to "I think we might be able to get rid of the cast validation which I believe would help reduce the inconsistency which you've pointed out." That statement is talking about the check that exists to ensure that after casting from the yaml interpreted type to the Attribute's specified type, the objects are equivalent. |
If one specifies an attribute to be of type
str
, they cannot then enter a valid string that looks like an integer to that attribute in their stream.For example:
Instead, if the user wants to supply (what is ostensibly) an
int
to a string attribute, they have to use quotes around the value. But this is strange, because quotes are not needed in other cases. For instance, if a user supplies something that obviously looks like a string to a string attribute, quotes are not needed:It would be nice if Yamlize would fully recognize that the
type=str
parameter being passed toAttribute
means that whatever the user provides, even if it looks like anint
or anything else, it should be coerced to astr
.At the least, the printed error could be changed to be more meaningful. Right now it says:
and this is confusing because the two printed values look exactly the same.
The text was updated successfully, but these errors were encountered: