Anybody else running into this? Pylance thinks this code is unreachable but it is. Seems like it’s due to the type-hinting. It thinks that because we declare a variable with type hint of “int”, it must only be an int.
def test_func():
a: int = "hello"
if not isinstance(a, int):
raise ValueError("Not an integer")
def test_func2():
a = "hello"
if not isinstance(a, int):
raise ValueError("Not an integer")
In test_func()
, variable a
has type hint int
, whereas in test_func2()
, it does not.
(See screenshot that shows the “grayed out” raise
line).
Feels like this only recently happened… vscode Version: 1.91.0, MacOS Ventura 13.2.