quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

Python fails for Union[bool, float]

Open DOsinga opened this issue 3 years ago • 0 comments

If I generate python code from a typescript definition like:

value: boolean | string | number | null;

The corresponding python code parser has something like:

value = from_union(
        [from_none, from_float, from_bool, from_str], obj.get("value")
    )

So it tries float before boolean, even though boolean is mentioned in the definition first. And since False and True both can be converted to floats in Python, you end up with 1.0 or 0.0 as a value after conversion instead of True or False

DOsinga avatar May 04 '22 23:05 DOsinga