from typing import reveal_type
def f(x: int | bool): # does not narrow
if type(x) is bool:
x = 42
reveal_type(x)
def g(x: int | None): # works OK
if x is None:
x = 42
reveal_type(x)
INFO revealed type: bool | int [reveal-type]
--> /tmp/foo.py:6:14
|
6 | reveal_type(x)
| ---
|
INFO revealed type: int [reveal-type]
--> /tmp/foo.py:12:14
|
12 | reveal_type(x)
| ---
|
INFO 0 errors
Describe the Bug
Reproducer:
Output:
Sandbox Link
No response
(Only applicable for extension issues) IDE Information
No response