3 ms·
It shows on the docs how to decode ‘a: null’ with the schema so I’m missing the part where you can’t use null.
by hombre_fatal 4y ago
It shows on the docs how to decode ‘a: null’ with the schema so I’m missing the part where you can’t use null.
- Dylan16807 4y agoOh I think I found the page you mean? https://hitchdev.com/strictyaml/using/alpha/scalar/empty/ https://hitchdev.com/strictyaml/using/alpha/scalar/empty/ It looks like you need to use an empty string and you can tell it to translate to None. That's better than nothing, but it's still basically an inability to use actual null here.
- hombre_fatal 4y agoI think I'm misunderstanding you, but StrictYAML's biggest departure from YAML is that it doesn't try to guess types at all. Everything is decoded as a string by default until you specify otherwise with its schema system. Here you can use `NullNone` to parse `null` into None. from strictyaml import Map, NullNone, Int, load schema = Map({"a": NullNone() | Int()}) load("a: null", schema) == {"a": None} load("a: 7777", schema) == {"a": 7777}
- Dylan16807 4y agoIt doesn't guess, but also the data can't tell it. It's not just that you get a string by default, it's that everything starts as a string and then goes through post-processing. If you want to distinguish between 'any string' and 'not a string', you can't. > Here you can use `NullNone` to parse `null` into None. That's the worst possible outcome for poor Christopher Null. The best you can do for him is use "a:" to mean null but at that point you're not really dealing with nulls, you've just gone with strings and used an empty string.