
2 Sep
2020
2 Sep
'20
9:11 p.m.
My 2 cents from a user's perspective.
Am 02.09.20 um 20:26 schrieb Guido van Rossum:
Consider these two similar functions:
from typing import Union def f() -> int: x: Union[int, str] = 42 return x # Error here def g() -> int: x: Union[int, str] x = 42 return x # But not here
The latter is very surprising to me. I would expect an error here, since Union[int, str] is not a sub-type of int. I would also expect it to be consistent with the first example.
There's another twist (note the return type is str here):
from typing import Any def h() -> str: x: Any = 42 return x
This is an error in pyre but not in mypy, pytype or pyright. And for good measure the other variant:
I wouldn't expect an error (especially not with default options). Any is compatible with all other types and is supposed to be a "free out of jail card" in case of type problems.
def i() -> str: x: Any x = 42 return x
This is accepted by mypy and pyright, but an error to pyre and pytype.
Same here.
- Sebastian