We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I used version: 1.6.1. The following program is correct:
1.6.1
s = "mode: default" schema_map = { "mode": sy.Str(), sy.Optional("duration", default=None, drop_if_none=False): sy.EmptyNone() | sy.Float(), } config_yaml = sy.load( yaml_string=s, schema=sy.Map(schema_map), )
But when I change the type order of optional duration like following:
duration
s = "mode: default" schema_map = { "mode": sy.Str(), sy.Optional("duration", default=None, drop_if_none=False): sy.Float() | sy.EmptyNone(), } config_yaml = sy.load( yaml_string=s, schema=sy.Map(schema_map), )
then there would be an error, here is the error log:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ../vendor/lib/python3.10/site-packages/strictyaml/parser.py:323: in load return generic_load(yaml_string, schema=schema, label=label) ../vendor/lib/python3.10/site-packages/strictyaml/parser.py:301: in generic_load return schema(YAMLChunk(document, label=label)) ../vendor/lib/python3.10/site-packages/strictyaml/validators.py:17: in __call__ self.validate(chunk) ../vendor/lib/python3.10/site-packages/strictyaml/compound.py:180: in validate new_value = value_validator( ../vendor/lib/python3.10/site-packages/strictyaml/validators.py:107: in __call__ result = self._validator_a(chunk) ../vendor/lib/python3.10/site-packages/strictyaml/scalar.py:27: in __call__ return YAML(chunk, validator=self) ../vendor/lib/python3.10/site-packages/strictyaml/representation.py:63: in __init__ self._value = validator.validate(value) ../vendor/lib/python3.10/site-packages/strictyaml/scalar.py:30: in validate return self.validate_scalar(chunk) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = Float() chunk = <strictyaml.yamllocation.YAMLChunk object at 0x7f64f2212aa0> def validate_scalar(self, chunk): val = chunk.contents if utils.is_infinity(val) or utils.is_not_a_number(val): val = val.replace(".", "") elif not utils.is_decimal(val): chunk.expecting_but_found("when expecting a float") # Only Python 3.6+ supports underscores in numeric literals > return float(val.replace("_", "")) E ValueError: could not convert string to float: '' ../vendor/lib/python3.10/site-packages/strictyaml/scalar.py:230: ValueError
But if changing sy.Float() to sy.Int(), this error would not arise.
sy.Float()
sy.Int()
The text was updated successfully, but these errors were encountered:
is_decimal is using regex pattern which matches empty string and therefore returns False Positive result.
is_decimal
Adding two lines to is_decimal before existing return ...:
return ...
if not value: return False
Would fix the issue.
I would do a PR, but it looks like they are not processed / handled for now.
Sorry, something went wrong.
@wikiped Thanks!
No branches or pull requests
I used version:
1.6.1
. The following program is correct:But when I change the type order of optional
duration
like following:then there would be an error, here is the error log:
But if changing
sy.Float()
tosy.Int()
, this error would not arise.The text was updated successfully, but these errors were encountered: