Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c30573e

Browse filesBrowse files
ilevkivskyiwesleywright
authored andcommitted
Fix literal context for ternary expressions (for real) (#18545)
I am not waiting for review as the fix is obvious. The only annoying thing is that we had an exact test as in the repro but it passed accidentally because we use builtins fixtures.
1 parent 23d862d commit c30573e
Copy full SHA for c30573e

File tree

3 files changed

+3
-2
lines changed
Filter options

3 files changed

+3
-2
lines changed

‎mypy/checker.py

Copy file name to clipboardExpand all lines: mypy/checker.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4372,7 +4372,7 @@ def check_simple_assignment(
43724372
if (
43734373
isinstance(get_proper_type(lvalue_type), UnionType)
43744374
# Skip literal types, as they have special logic (for better errors).
4375-
and not isinstance(get_proper_type(rvalue_type), LiteralType)
4375+
and not is_literal_type_like(rvalue_type)
43764376
and not self.simple_rvalue(rvalue)
43774377
):
43784378
# Try re-inferring r.h.s. in empty context, and use that if it

‎test-data/unit/check-literal.test

Copy file name to clipboardExpand all lines: test-data/unit/check-literal.test
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2984,7 +2984,7 @@ class C(Base):
29842984
sep = "a" if int() else "b"
29852985
reveal_type(sep) # N: Revealed type is "Union[Literal['a'], Literal['b']]"
29862986
return super().feed_data(sep)
2987-
[builtins fixtures/tuple.pyi]
2987+
[builtins fixtures/primitives.pyi]
29882988

29892989
[case testLiteralInsideAType]
29902990
from typing_extensions import Literal

‎test-data/unit/fixtures/primitives.pyi

Copy file name to clipboardExpand all lines: test-data/unit/fixtures/primitives.pyi
+1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.