From 58149d6bd63df38c5eff7ea15b3fcef5f8adf35d Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sun, 14 Dec 2025 15:25:33 -0800 Subject: [PATCH] Fix another merge race Also remove some redundant tests --- test-data/unit/check-literal.test | 64 +++++++++--------------------- test-data/unit/check-optional.test | 2 +- 2 files changed, 19 insertions(+), 47 deletions(-) diff --git a/test-data/unit/check-literal.test b/test-data/unit/check-literal.test index 0135a6816042..d71370eb4191 100644 --- a/test-data/unit/check-literal.test +++ b/test-data/unit/check-literal.test @@ -2949,48 +2949,20 @@ reveal_type(C().collection) # N: Revealed type is "builtins.list[Literal['word' reveal_type(C().word) # N: Revealed type is "Literal['word']" [builtins fixtures/tuple.pyi] -[case testStringLiteralTernary] -# https://github.com/python/mypy/issues/19534 -def test(b: bool) -> None: - l = "foo" if b else "bar" - reveal_type(l) # N: Revealed type is "builtins.str" -[builtins fixtures/tuple.pyi] - -[case testintLiteralTernary] -# https://github.com/python/mypy/issues/19534 -def test(b: bool) -> None: - l = 0 if b else 1 - reveal_type(l) # N: Revealed type is "builtins.int" -[builtins fixtures/tuple.pyi] - [case testStringIntUnionTernary] # https://github.com/python/mypy/issues/19534 def test(b: bool) -> None: l = 1 if b else "a" - reveal_type(l) # N: Revealed type is "Union[builtins.int, builtins.str]" + reveal_type(l) # N: Revealed type is "builtins.int | builtins.str" [builtins fixtures/tuple.pyi] [case testListComprehensionTernary] # https://github.com/python/mypy/issues/19534 def test(b: bool) -> None: l = [1] if b else ["a"] - reveal_type(l) # N: Revealed type is "Union[builtins.list[builtins.int], builtins.list[builtins.str]]" + reveal_type(l) # N: Revealed type is "builtins.list[builtins.int] | builtins.list[builtins.str]" [builtins fixtures/list.pyi] -[case testSetComprehensionTernary] -# https://github.com/python/mypy/issues/19534 -def test(b: bool) -> None: - s = {1} if b else {"a"} - reveal_type(s) # N: Revealed type is "Union[builtins.set[builtins.int], builtins.set[builtins.str]]" -[builtins fixtures/set.pyi] - -[case testDictComprehensionTernary] -# https://github.com/python/mypy/issues/19534 -def test(b: bool) -> None: - d = {1:1} if "" else {"a": "a"} - reveal_type(d) # N: Revealed type is "Union[builtins.dict[builtins.int, builtins.int], builtins.dict[builtins.str, builtins.str]]" -[builtins fixtures/dict.pyi] - [case testLambdaTernary] from typing import TypeVar, Union, Callable, reveal_type @@ -3034,10 +3006,10 @@ class B: def test_static_with_attr(x: B) -> None: def foo(t: A) -> None: ... - 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" - 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" - 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" - r2 = NOOP if x.attr is None else (lambda: foo(x.attr)) # E: Argument 1 to "foo" has incompatible type "Optional[A]"; expected "A" + 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" + 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" + 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" + r2 = NOOP if x.attr is None else (lambda: foo(x.attr)) # E: Argument 1 to "foo" has incompatible type "A | None"; expected "A" reveal_type(l2) # N: Revealed type is "def ()" reveal_type(r2) # N: Revealed type is "def ()" @@ -3045,12 +3017,12 @@ def test_generic_with_attr(x: B) -> None: T = TypeVar("T") def bar(t: T) -> T: return t - 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]") - 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]") + 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]") + 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]") l2 = (lambda: bar(x.attr)) if x.attr is None else NOOP r2 = NOOP if x.attr is not None else (lambda: bar(x.attr)) - reveal_type(l2) # N: Revealed type is "def () -> Union[__main__.A, None]" - reveal_type(r2) # N: Revealed type is "def () -> Union[__main__.A, None]" + reveal_type(l2) # N: Revealed type is "def () -> __main__.A | None" + reveal_type(r2) # N: Revealed type is "def () -> __main__.A | None" [case testLambdaTernaryDoubleIndirectAttribute] # fails due to binder issue inside `check_func_def` @@ -3067,10 +3039,10 @@ class C: def test_static_with_attr(x: C) -> None: def foo(t: A) -> None: ... - 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" - 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" - 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" - 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" + 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" + 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" + 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" + 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" reveal_type(l2) # N: Revealed type is "def ()" reveal_type(r2) # N: Revealed type is "def ()" @@ -3078,12 +3050,12 @@ def test_generic_with_attr(x: C) -> None: T = TypeVar("T") def bar(t: T) -> T: return t - 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]") - 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]") + 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]") + 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]") l2 = (lambda: bar(x.attr.attr)) if x.attr.attr is None else NOOP r2 = NOOP if x.attr.attr is not None else (lambda: bar(x.attr.attr)) - reveal_type(l2) # N: Revealed type is "def () -> Union[__main__.A, None]" - reveal_type(r2) # N: Revealed type is "def () -> Union[__main__.A, None]" + reveal_type(l2) # N: Revealed type is "def () -> __main__.A | None" + reveal_type(r2) # N: Revealed type is "def () -> __main__.A | None" [case testLiteralTernaryUnionNarrowing] diff --git a/test-data/unit/check-optional.test b/test-data/unit/check-optional.test index d5675ac23e58..393de00c41d5 100644 --- a/test-data/unit/check-optional.test +++ b/test-data/unit/check-optional.test @@ -430,7 +430,7 @@ reveal_type(l) # N: Revealed type is "builtins.list[typing.Generator[builtins.s [case testNoneListTernary] # https://github.com/python/mypy/issues/19534 x = [None] if "" else [1] -reveal_type(x) # N: Revealed type is "Union[builtins.list[None], builtins.list[builtins.int]]" +reveal_type(x) # N: Revealed type is "builtins.list[None] | builtins.list[builtins.int]" [builtins fixtures/list.pyi] [case testListIncompatibleErrorMessage]