@@ -2077,9 +2077,7 @@ class A: pass
2077
2077
2078
2078
def foo1(x: Union[A, str, None]) -> None:
2079
2079
if x is None:
2080
- # Since None is a subtype of all types in no-strict-optional,
2081
- # we can't really narrow the type here
2082
- reveal_type(x) # E: Revealed type is 'Union[__main__.A, builtins.str, None]'
2080
+ reveal_type(x) # E: Revealed type is 'None'
2083
2081
elif isinstance(x, A):
2084
2082
# Note that Union[None, A] == A in no-strict-optional
2085
2083
reveal_type(x) # E: Revealed type is '__main__.A'
@@ -2088,12 +2086,12 @@ def foo1(x: Union[A, str, None]) -> None:
2088
2086
2089
2087
def foo2(x: Optional[str]) -> None:
2090
2088
if x is None:
2091
- reveal_type(x) # E: Revealed type is 'Union[builtins.str, None] '
2089
+ reveal_type(x) # E: Revealed type is 'None'
2092
2090
elif isinstance(x, A):
2093
2091
# Mypy should, however, be able to skip impossible cases
2094
2092
reveal_type(x)
2095
2093
else:
2096
- reveal_type(x) # E: Revealed type is 'Union[ builtins.str, None] '
2094
+ reveal_type(x) # E: Revealed type is 'builtins.str'
2097
2095
[builtins fixtures/isinstance.pyi]
2098
2096
2099
2097
[case testNoneCheckDoesNotNarrowWhenUsingTypeVars]
@@ -2153,7 +2151,7 @@ def bar(x: Union[List[str], List[int], None]) -> None:
2153
2151
from typing import Union, Optional, List
2154
2152
2155
2153
# This test is the same as the one above, except for strict-optional.
2156
- # It isn't testing anything explicitly and mostly exists for the sake
2154
+ # It isn't testing anything explicitly and mostly exists for the sake
2157
2155
# of completeness.
2158
2156
2159
2157
def foo(x: Optional[List[str]]) -> None:
@@ -2166,4 +2164,3 @@ def bar(x: Union[List[str], List[int], None]) -> None:
2166
2164
assert isinstance(x, list)
2167
2165
reveal_type(x) # E: Revealed type is 'Union[builtins.list[builtins.str], builtins.list[builtins.int]]'
2168
2166
[builtins fixtures/isinstancelist.pyi]
2169
-
0 commit comments