Steven D'Aprano wrote:
but the type checker should infer that if you assign None to a variable
which is declared int, you must have meant Optional[int] rather than just
int.
This seems to be equivalent to saying that *all* types are
Optional, in which case what point is there in having Optional
at all?
Indeed, that's often the best way, except for the redundant type hint,
which makes you That Guy:
x: int = 0 # set x to the int 0
But you've shown in an earlier example that such a hint is
*not* always redundant, e.g.
x = 0
x = 2.5
is legal and useful, whereas
x: int = 0
x = 2.5
ought to be a type error.
--
Greg
--
https://mail.python.org/mailman/listinfo/python-list