Hacker News new | past | comments | ask | show | jobs | submit login

So the documentation talks about the problem of 「null」being confused with 「"null"」.

But the solution is to make it impossible to write 「null」 at all? I don't think I would have suggested that one...




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.


Oh I think I found the page you mean? 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.


I 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}


It 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.


Simple solution: Make it impossible to write 「"null"」




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: