Closed
Description
- Mypy's current behaviour:
x: int | None
if x == None:
x # "Union[builtins.int, None]"
else:
x # "Union[builtins.int, None]"
- Pyright's current behaviour:
x: int | None
if x == None:
x # x is None
else:
x # x is int
- I think the ideal solution would be:
x: int | None
if x == None:
x # "Union[builtins.int, None]"
else:
x # "builtins.int"
This Mypy code comment seems to favour solution 2.
I am asking because if Mypy would follow solution 2 or 3, in
-based narrowing of optional types could be implemented more consistently.