Optional[int | float] is not a valid type annotation. I've changed it to just float because an int should be viewed as a subclass of float for typing purposes. But even if you wanted to express the union, the correct syntax would have been Optional[Union[int, float]], or the equivalent Union[int, float, None].
The only reason I touched this code at all is that the regular python interpreter throws an exception when trying to evaluate this annotation as part of running the simulator.
Optional[int | float] is a valid type annotation and the simulator works fine with it (otherwise CI would be broken on main right now). Union type expressions were introduced with Python 3.10 in 2021 (PEP 604). If you want to make it compatible with Python < 3.10 then go on, though it may be worth editing the commit message to be less confusing.
So https://peps.python.org/pep-0484/#the-numeric-tower states that float alone will, indeed, already cover int. Personally I'd prefer having it explicit, but my initial worry was that it's wrong - and it's not 🤪️
What's this change about? It doesn't seem right.
Optional[int | float]
is not a valid type annotation. I've changed it to justfloat
because anint
should be viewed as a subclass offloat
for typing purposes. But even if you wanted to express the union, the correct syntax would have beenOptional[Union[int, float]]
, or the equivalentUnion[int, float, None]
.The only reason I touched this code at all is that the regular python interpreter throws an exception when trying to evaluate this annotation as part of running the simulator.
Optional[int | float]
is a valid type annotation and the simulator works fine with it (otherwise CI would be broken on main right now). Union type expressions were introduced with Python 3.10 in 2021 (PEP 604). If you want to make it compatible with Python < 3.10 then go on, though it may be worth editing the commit message to be less confusing.So https://peps.python.org/pep-0484/#the-numeric-tower states that
float
alone will, indeed, already coverint
. Personally I'd prefer having it explicit, but my initial worry was that it's wrong - and it's not 🤪️