Skip to content

Commit 13916c8

Browse files
committed
Fix literal context for ternary expressions (for real)
1 parent 1eb9d4c commit 13916c8

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4469,7 +4469,7 @@ def check_simple_assignment(
44694469
if (
44704470
isinstance(get_proper_type(lvalue_type), UnionType)
44714471
# Skip literal types, as they have special logic (for better errors).
4472-
and not isinstance(get_proper_type(rvalue_type), LiteralType)
4472+
and not is_literal_type_like(rvalue_type)
44734473
and not self.simple_rvalue(rvalue)
44744474
):
44754475
# Try re-inferring r.h.s. in empty context, and use that if it

test-data/unit/check-literal.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2980,7 +2980,7 @@ class C(Base):
29802980
sep = "a" if int() else "b"
29812981
reveal_type(sep) # N: Revealed type is "Union[Literal['a'], Literal['b']]"
29822982
return super().feed_data(sep)
2983-
[builtins fixtures/tuple.pyi]
2983+
[builtins fixtures/primitives.pyi]
29842984

29852985
[case testLiteralInsideAType]
29862986
from typing_extensions import Literal

test-data/unit/fixtures/primitives.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class int:
1919
def __init__(self, x: object = ..., base: int = ...) -> None: pass
2020
def __add__(self, i: int) -> int: pass
2121
def __rmul__(self, x: int) -> int: pass
22+
def __bool__(self) -> bool: pass
2223
class float:
2324
def __float__(self) -> float: pass
2425
def __add__(self, x: float) -> float: pass

0 commit comments

Comments
 (0)