-
Notifications
You must be signed in to change notification settings - Fork 239
Labels
narrowingIssues with narrowing - root cause is usually narrowing, flow handling, or bothIssues with narrowing - root cause is usually narrowing, flow handling, or both
Description
Describe the Bug
In the following example, I expected reveal_type(x) to output int, but the actual output was dict[Literal['value'], int] | int.
As a result, the type checker gives a [bad-return] error.
from typing import Literal, reveal_type
def get_value(x: dict[Literal['value'], int] | int) -> int | None:
if isinstance(x, dict):
return x.get('value')
reveal_type(x) # Revealed type is `dict[Literal['value'], int] | int`, but it should be `int`
return x(This example works as expected in Pyright.)
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
Metadata
Metadata
Assignees
Labels
narrowingIssues with narrowing - root cause is usually narrowing, flow handling, or bothIssues with narrowing - root cause is usually narrowing, flow handling, or both