How to make Pyright obey my annotated type instead of narrowing it?
I was testing out typing.assert_type() in Pyright: from typing import assert_type value: int = 10 assert_type(value, int) I expected no warning, but got one: Error: "assert_type" mismatch: expected "int" but received "Literal[10]". I tested the type: reveal_type(value) # Type of "value" is "Literal[10]" Why does Pyright narrow value to Literal[10] despite my explicit int annotation? How can I avoid this? I also tested with a function argument, as shown in the docs. This worked as expected: def foo(value: int): assert_type(value, int) # no type checker error So how come it fails in my original
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.