Traceback (most recent call last):
File "/tmp/sessions/4a8af4124d815246/main.py", line 71, in <module>
print(coordinate.to_dict())
File "/tmp/sessions/4a8af4124d815246/main.py", line 53, in to_dict
result["latitude"] = from_union([to_float, from_none], self.latitude)
File "/tmp/sessions/4a8af4124d815246/main.py", line 24, in from_union
assert False
AssertionError
This should be expected to work since JSON schema spec defines the number type like this:
The number type is used for any numeric type, either integers or floating point numbers.
Also, note that in Python the "float" type hint also deems an int as acceptable:
Rather than requiring that users write import numbers and then use numbers.Float etc., this PEP proposes a straightforward shortcut that is almost as effective: when an argument is annotated as having type float, an argument of type int is acceptable
Consider the example JSON schema:
Quicktype generates the following Python code:
The problem is that if you create an instance of
Coordinate
with literal integer parameters and then callto_dict()
:then you get an AssertionError:
This should be expected to work since JSON schema spec defines the
number
type like this:Also, note that in Python the "float" type hint also deems an int as acceptable: