-
Notifications
You must be signed in to change notification settings - Fork 219
Closed
astral-sh/ruff
#22894Milestone
Description
We fail to do TypedDict tagged-union narrowing on this example:
from typing import TypedDict, Literal
class Ok(TypedDict):
result: Literal["ok"]
payload: bytes
class Err(TypedDict):
result: Literal["error"]
message: str
type Response = Ok | Err
def read(res: Response) -> bytes:
if res["result"] == "ok":
return res["payload"]
else:
raise Exception(res["message"])But we do narrow if res: Ok | Err, or if Response = Ok | Err (legacy type alias instead of PEP 695 type alias).
We aren't handling a PEP 695 type alias as a union in narrowing. We should fix this, and also look for other cases in narrowing where we special-case unions, and ensure a PEP 695 alias to a union is handled the same way.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels