You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
-
2994
2966
[case testLambdaTernary]
2995
2967
from typing import TypeVar, Union, Callable, reveal_type
2996
2968
@@ -3034,23 +3006,23 @@ class B:
3034
3006
def test_static_with_attr(x: B) -> None:
3035
3007
def foo(t: A) -> None: ...
3036
3008
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"
3041
3013
reveal_type(l2) # N: Revealed type is "def ()"
3042
3014
reveal_type(r2) # N: Revealed type is "def ()"
3043
3015
3044
3016
def test_generic_with_attr(x: B) -> None:
3045
3017
T = TypeVar("T")
3046
3018
def bar(t: T) -> T: return t
3047
3019
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]")
3050
3022
l2 = (lambda: bar(x.attr)) if x.attr is None else NOOP
3051
3023
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"
3054
3026
3055
3027
[case testLambdaTernaryDoubleIndirectAttribute]
3056
3028
# fails due to binder issue inside `check_func_def`
@@ -3067,23 +3039,23 @@ class C:
3067
3039
def test_static_with_attr(x: C) -> None:
3068
3040
def foo(t: A) -> None: ...
3069
3041
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"
3074
3046
reveal_type(l2) # N: Revealed type is "def ()"
3075
3047
reveal_type(r2) # N: Revealed type is "def ()"
3076
3048
3077
3049
def test_generic_with_attr(x: C) -> None:
3078
3050
T = TypeVar("T")
3079
3051
def bar(t: T) -> T: return t
3080
3052
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]")
3083
3055
l2 = (lambda: bar(x.attr.attr)) if x.attr.attr is None else NOOP
3084
3056
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"
0 commit comments