Take this example code:
x="a"reveal_type(x)
assertxin ("a", "b", "c")
reveal_type(x)
y=20reveal_type(y)
asserty==10ory==20ory==50reveal_type(y)The current output of this is:
$ mypy x.py x.py:2: note: Revealed type is "builtins.str"x.py:4: note: Revealed type is "builtins.str"x.py:7: note: Revealed type is "builtins.int"x.py:9: note: Revealed type is "builtins.int"
If mypy were to support type narrowing using chained or statements and in statements, the output would look like:
$ mypy x.py x.py:4: note: Revealed type is "builtins.str"x.py:6: note: Revealed type is "Union[Literal['a'], Literal['b'], Literal['c']]"x.py:9: note: Revealed type is "builtins.int"x.py:11: note: Revealed type is "Union[Literal[10], Literal[20], Literal[50]]"
I think doing simple narrowing here would be relatively easy and very useful.
Take this example code:
The current output of this is:
If mypy were to support type narrowing using chained
orstatements andinstatements, the output would look like:I think doing simple narrowing here would be relatively easy and very useful.