Skip to content

Commit 6e449e7

Browse files
authored
Fix another merge race (#20413)
Also remove some redundant tests
1 parent 319d2a5 commit 6e449e7

File tree

2 files changed

+19
-47
lines changed

2 files changed

+19
-47
lines changed

test-data/unit/check-literal.test

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,48 +2949,20 @@ reveal_type(C().collection) # N: Revealed type is "builtins.list[Literal['word'
29492949
reveal_type(C().word) # N: Revealed type is "Literal['word']"
29502950
[builtins fixtures/tuple.pyi]
29512951

2952-
[case testStringLiteralTernary]
2953-
# https://github.com/python/mypy/issues/19534
2954-
def test(b: bool) -> None:
2955-
l = "foo" if b else "bar"
2956-
reveal_type(l) # N: Revealed type is "builtins.str"
2957-
[builtins fixtures/tuple.pyi]
2958-
2959-
[case testintLiteralTernary]
2960-
# https://github.com/python/mypy/issues/19534
2961-
def test(b: bool) -> None:
2962-
l = 0 if b else 1
2963-
reveal_type(l) # N: Revealed type is "builtins.int"
2964-
[builtins fixtures/tuple.pyi]
2965-
29662952
[case testStringIntUnionTernary]
29672953
# https://github.com/python/mypy/issues/19534
29682954
def test(b: bool) -> None:
29692955
l = 1 if b else "a"
2970-
reveal_type(l) # N: Revealed type is "Union[builtins.int, builtins.str]"
2956+
reveal_type(l) # N: Revealed type is "builtins.int | builtins.str"
29712957
[builtins fixtures/tuple.pyi]
29722958

29732959
[case testListComprehensionTernary]
29742960
# https://github.com/python/mypy/issues/19534
29752961
def test(b: bool) -> None:
29762962
l = [1] if b else ["a"]
2977-
reveal_type(l) # N: Revealed type is "Union[builtins.list[builtins.int], builtins.list[builtins.str]]"
2963+
reveal_type(l) # N: Revealed type is "builtins.list[builtins.int] | builtins.list[builtins.str]"
29782964
[builtins fixtures/list.pyi]
29792965

2980-
[case testSetComprehensionTernary]
2981-
# https://github.com/python/mypy/issues/19534
2982-
def test(b: bool) -> None:
2983-
s = {1} if b else {"a"}
2984-
reveal_type(s) # N: Revealed type is "Union[builtins.set[builtins.int], builtins.set[builtins.str]]"
2985-
[builtins fixtures/set.pyi]
2986-
2987-
[case testDictComprehensionTernary]
2988-
# https://github.com/python/mypy/issues/19534
2989-
def test(b: bool) -> None:
2990-
d = {1:1} if "" else {"a": "a"}
2991-
reveal_type(d) # N: Revealed type is "Union[builtins.dict[builtins.int, builtins.int], builtins.dict[builtins.str, builtins.str]]"
2992-
[builtins fixtures/dict.pyi]
2993-
29942966
[case testLambdaTernary]
29952967
from typing import TypeVar, Union, Callable, reveal_type
29962968

@@ -3034,23 +3006,23 @@ class B:
30343006
def test_static_with_attr(x: B) -> None:
30353007
def foo(t: A) -> None: ...
30363008

3037-
l1: Callable[[], None] = (lambda: foo(x.attr)) if x.attr is not None else NOOP # E: Argument 1 to "foo" has incompatible type "Optional[A]"; expected "A"
3038-
r1: Callable[[], None] = NOOP if x.attr is None else (lambda: foo(x.attr)) # E: Argument 1 to "foo" has incompatible type "Optional[A]"; expected "A"
3039-
l2 = (lambda: foo(x.attr)) if x.attr is not None else NOOP # E: Argument 1 to "foo" has incompatible type "Optional[A]"; expected "A"
3040-
r2 = NOOP if x.attr is None else (lambda: foo(x.attr)) # E: Argument 1 to "foo" has incompatible type "Optional[A]"; expected "A"
3009+
l1: Callable[[], None] = (lambda: foo(x.attr)) if x.attr is not None else NOOP # E: Argument 1 to "foo" has incompatible type "A | None"; expected "A"
3010+
r1: Callable[[], None] = NOOP if x.attr is None else (lambda: foo(x.attr)) # E: Argument 1 to "foo" has incompatible type "A | None"; expected "A"
3011+
l2 = (lambda: foo(x.attr)) if x.attr is not None else NOOP # E: Argument 1 to "foo" has incompatible type "A | None"; expected "A"
3012+
r2 = NOOP if x.attr is None else (lambda: foo(x.attr)) # E: Argument 1 to "foo" has incompatible type "A | None"; expected "A"
30413013
reveal_type(l2) # N: Revealed type is "def ()"
30423014
reveal_type(r2) # N: Revealed type is "def ()"
30433015

30443016
def test_generic_with_attr(x: B) -> None:
30453017
T = TypeVar("T")
30463018
def bar(t: T) -> T: return t
30473019

3048-
l1: Callable[[], None] = (lambda: bar(x.attr)) if x.attr is None else NOOP # E: Incompatible types in assignment (expression has type "Callable[[], Optional[A]]", variable has type "Callable[[], None]")
3049-
r1: Callable[[], None] = NOOP if x.attr is not None else (lambda: bar(x.attr)) # E: Incompatible types in assignment (expression has type "Callable[[], Optional[A]]", variable has type "Callable[[], None]")
3020+
l1: Callable[[], None] = (lambda: bar(x.attr)) if x.attr is None else NOOP # E: Incompatible types in assignment (expression has type "Callable[[], A | None]", variable has type "Callable[[], None]")
3021+
r1: Callable[[], None] = NOOP if x.attr is not None else (lambda: bar(x.attr)) # E: Incompatible types in assignment (expression has type "Callable[[], A | None]", variable has type "Callable[[], None]")
30503022
l2 = (lambda: bar(x.attr)) if x.attr is None else NOOP
30513023
r2 = NOOP if x.attr is not None else (lambda: bar(x.attr))
3052-
reveal_type(l2) # N: Revealed type is "def () -> Union[__main__.A, None]"
3053-
reveal_type(r2) # N: Revealed type is "def () -> Union[__main__.A, None]"
3024+
reveal_type(l2) # N: Revealed type is "def () -> __main__.A | None"
3025+
reveal_type(r2) # N: Revealed type is "def () -> __main__.A | None"
30543026

30553027
[case testLambdaTernaryDoubleIndirectAttribute]
30563028
# fails due to binder issue inside `check_func_def`
@@ -3067,23 +3039,23 @@ class C:
30673039
def test_static_with_attr(x: C) -> None:
30683040
def foo(t: A) -> None: ...
30693041

3070-
l1: Callable[[], None] = (lambda: foo(x.attr.attr)) if x.attr.attr is not None else NOOP # E: Argument 1 to "foo" has incompatible type "Optional[A]"; expected "A"
3071-
r1: Callable[[], None] = NOOP if x.attr.attr is None else (lambda: foo(x.attr.attr)) # E: Argument 1 to "foo" has incompatible type "Optional[A]"; expected "A"
3072-
l2 = (lambda: foo(x.attr.attr)) if x.attr.attr is not None else NOOP # E: Argument 1 to "foo" has incompatible type "Optional[A]"; expected "A"
3073-
r2 = NOOP if x.attr.attr is None else (lambda: foo(x.attr.attr)) # E: Argument 1 to "foo" has incompatible type "Optional[A]"; expected "A"
3042+
l1: Callable[[], None] = (lambda: foo(x.attr.attr)) if x.attr.attr is not None else NOOP # E: Argument 1 to "foo" has incompatible type "A | None"; expected "A"
3043+
r1: Callable[[], None] = NOOP if x.attr.attr is None else (lambda: foo(x.attr.attr)) # E: Argument 1 to "foo" has incompatible type "A | None"; expected "A"
3044+
l2 = (lambda: foo(x.attr.attr)) if x.attr.attr is not None else NOOP # E: Argument 1 to "foo" has incompatible type "A | None"; expected "A"
3045+
r2 = NOOP if x.attr.attr is None else (lambda: foo(x.attr.attr)) # E: Argument 1 to "foo" has incompatible type "A | None"; expected "A"
30743046
reveal_type(l2) # N: Revealed type is "def ()"
30753047
reveal_type(r2) # N: Revealed type is "def ()"
30763048

30773049
def test_generic_with_attr(x: C) -> None:
30783050
T = TypeVar("T")
30793051
def bar(t: T) -> T: return t
30803052

3081-
l1: Callable[[], None] = (lambda: bar(x.attr.attr)) if x.attr.attr is None else NOOP # E: Incompatible types in assignment (expression has type "Callable[[], Optional[A]]", variable has type "Callable[[], None]")
3082-
r1: Callable[[], None] = NOOP if x.attr.attr is not None else (lambda: bar(x.attr.attr)) # E: Incompatible types in assignment (expression has type "Callable[[], Optional[A]]", variable has type "Callable[[], None]")
3053+
l1: Callable[[], None] = (lambda: bar(x.attr.attr)) if x.attr.attr is None else NOOP # E: Incompatible types in assignment (expression has type "Callable[[], A | None]", variable has type "Callable[[], None]")
3054+
r1: Callable[[], None] = NOOP if x.attr.attr is not None else (lambda: bar(x.attr.attr)) # E: Incompatible types in assignment (expression has type "Callable[[], A | None]", variable has type "Callable[[], None]")
30833055
l2 = (lambda: bar(x.attr.attr)) if x.attr.attr is None else NOOP
30843056
r2 = NOOP if x.attr.attr is not None else (lambda: bar(x.attr.attr))
3085-
reveal_type(l2) # N: Revealed type is "def () -> Union[__main__.A, None]"
3086-
reveal_type(r2) # N: Revealed type is "def () -> Union[__main__.A, None]"
3057+
reveal_type(l2) # N: Revealed type is "def () -> __main__.A | None"
3058+
reveal_type(r2) # N: Revealed type is "def () -> __main__.A | None"
30873059

30883060

30893061
[case testLiteralTernaryUnionNarrowing]

test-data/unit/check-optional.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ reveal_type(l) # N: Revealed type is "builtins.list[typing.Generator[builtins.s
430430
[case testNoneListTernary]
431431
# https://github.com/python/mypy/issues/19534
432432
x = [None] if "" else [1]
433-
reveal_type(x) # N: Revealed type is "Union[builtins.list[None], builtins.list[builtins.int]]"
433+
reveal_type(x) # N: Revealed type is "builtins.list[None] | builtins.list[builtins.int]"
434434
[builtins fixtures/list.pyi]
435435

436436
[case testListIncompatibleErrorMessage]

0 commit comments

Comments
 (0)