- Mypy's current behaviour:
x: int|Noneifx==None:
x# "Union[builtins.int, None]"else:
x# "Union[builtins.int, None]"
- Pyright's current behaviour:
x: int|Noneifx==None:
x# x is Noneelse:
x# x is int
- I think the ideal solution would be:
x: int|Noneifx==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.
Related pull requests: #15760#17154#17044.
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.Related pull requests: #15760#17154#17044.