-
Notifications
You must be signed in to change notification settings - Fork 219
Closed
astral-sh/ruff
#23084Labels
narrowingrelated to flow-sensitive type narrowingrelated to flow-sensitive type narrowing
Description
Summary
Binary operators narrow only their left operands. Example:
$ cat >bug.py <<'# EOF'
from typing import Literal
def _(t: Literal[True], tn: Literal[True] | None):
if tn is t:
+tn
if t is tn:
+tn
# EOF
$ ty check bug.py
error[unsupported-operator]: Unary operator `+` is not supported for object of type `Literal[True] | None`
--> bug.py:6:9
|
4 | +tn
5 | if t is tn:
6 | +tn
| ^^^
|
info: rule `unsupported-operator` is enabled by default
Found 1 diagnosticVersion
ty 0.0.15 (eb43dff 2026-02-04)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
narrowingrelated to flow-sensitive type narrowingrelated to flow-sensitive type narrowing