typing.TypeGuard
not eliminating type possibility when branching.
#3450
Labels
as designed
Not a bug, working as intended
Note: if you are reporting a wrong signature of a function or a class in the standard library, then the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues.
Describe the bug
When using TypeGuards to determine a type, they do not exhaust the type in following type checks.
Expected behavior
After a type is used in one branch, it will not show up in another.
Screenshots or Code
Current
Expected
VS Code extension or command-line
Both the cli and the VSCode extension report the same behavior.
CLI:
pyright 1.1.245
Extension:
v1.1.245
Additional context
I noticed that other type checkers like mypy and pylance both have this "issue", and was wondering if this is the intended behavior. If so, is there any way to get rid of more complex types when branching (such as
Callable[..., int]
vsCallable[..., Awaitable[int]]
?The text was updated successfully, but these errors were encountered: