@@ -1392,13 +1392,13 @@ else: |
1392 | 1392 | reveal_type(val) # N: Revealed type is "Union[__main__.A, None]" |
1393 | 1393 |
|
1394 | 1394 | if val in (None,): |
1395 | | - reveal_type(val) # N: Revealed type is "None" |
| 1395 | + reveal_type(val) # N: Revealed type is "Union[__main__.A, None]" |
1396 | 1396 | else: |
1397 | 1397 | reveal_type(val) # N: Revealed type is "Union[__main__.A, None]" |
1398 | 1398 | if val not in (None,): |
1399 | 1399 | reveal_type(val) # N: Revealed type is "Union[__main__.A, None]" |
1400 | 1400 | else: |
1401 | | - reveal_type(val) # N: Revealed type is "None" |
| 1401 | + reveal_type(val) # N: Revealed type is "Union[__main__.A, None]" |
1402 | 1402 | [builtins fixtures/primitives.pyi] |
1403 | 1403 |
|
1404 | 1404 | [case testNarrowingWithTupleOfTypes] |
@@ -2130,111 +2130,3 @@ else: |
2130 | 2130 |
|
2131 | 2131 | [typing fixtures/typing-medium.pyi] |
2132 | 2132 | [builtins fixtures/ops.pyi] |
2133 | | - |
2134 | | - |
2135 | | -[case testTypeNarrowingStringInLiteralUnion] |
2136 | | -from typing import Literal, Tuple |
2137 | | -typ: Tuple[Literal['a', 'b'], ...] = ('a', 'b') |
2138 | | -x: str = "hi!" |
2139 | | -if x in typ: |
2140 | | - reveal_type(x) # N: Revealed type is "Union[Literal['a'], Literal['b']]" |
2141 | | -else: |
2142 | | - reveal_type(x) # N: Revealed type is "builtins.str" |
2143 | | -[builtins fixtures/tuple.pyi] |
2144 | | -[typing fixtures/typing-medium.pyi] |
2145 | | - |
2146 | | -[case testTypeNarrowingStringInLiteralUnionSubset] |
2147 | | -from typing import Literal, Tuple |
2148 | | -typeAlpha: Tuple[Literal['a', 'b', 'c'], ...] = ('a', 'b') |
2149 | | -strIn: str = "b" |
2150 | | -strOut: str = "c" |
2151 | | -if strIn in typeAlpha: |
2152 | | - reveal_type(strIn) # N: Revealed type is "Union[Literal['a'], Literal['b'], Literal['c']]" |
2153 | | -else: |
2154 | | - reveal_type(strIn) # N: Revealed type is "builtins.str" |
2155 | | -if strOut in typeAlpha: |
2156 | | - reveal_type(strOut) # N: Revealed type is "Union[Literal['a'], Literal['b'], Literal['c']]" |
2157 | | -else: |
2158 | | - reveal_type(strOut) # N: Revealed type is "builtins.str" |
2159 | | -[builtins fixtures/primitives.pyi] |
2160 | | -[typing fixtures/typing-medium.pyi] |
2161 | | - |
2162 | | -[case testNarrowingStringNotInLiteralUnion] |
2163 | | -from typing import Literal, Tuple |
2164 | | -typeAlpha: Tuple[Literal['a', 'b', 'c'],...] = ('a', 'b', 'c') |
2165 | | -strIn: str = "c" |
2166 | | -strOut: str = "d" |
2167 | | -if strIn not in typeAlpha: |
2168 | | - reveal_type(strIn) # N: Revealed type is "builtins.str" |
2169 | | -else: |
2170 | | - reveal_type(strIn) # N: Revealed type is "Union[Literal['a'], Literal['b'], Literal['c']]" |
2171 | | -if strOut in typeAlpha: |
2172 | | - reveal_type(strOut) # N: Revealed type is "Union[Literal['a'], Literal['b'], Literal['c']]" |
2173 | | -else: |
2174 | | - reveal_type(strOut) # N: Revealed type is "builtins.str" |
2175 | | -[builtins fixtures/primitives.pyi] |
2176 | | -[typing fixtures/typing-medium.pyi] |
2177 | | - |
2178 | | -[case testNarrowingStringInLiteralUnionDontExpand] |
2179 | | -from typing import Literal, Tuple |
2180 | | -typeAlpha: Tuple[Literal['a', 'b', 'c'], ...] = ('a', 'b', 'c') |
2181 | | -strIn: Literal['c'] = "c" |
2182 | | -reveal_type(strIn) # N: Revealed type is "Literal['c']" |
2183 | | -#Check we don't expand a Literal into the Union type |
2184 | | -if strIn not in typeAlpha: |
2185 | | - reveal_type(strIn) # N: Revealed type is "Literal['c']" |
2186 | | -else: |
2187 | | - reveal_type(strIn) # N: Revealed type is "Literal['c']" |
2188 | | -[builtins fixtures/primitives.pyi] |
2189 | | -[typing fixtures/typing-medium.pyi] |
2190 | | - |
2191 | | -[case testTypeNarrowingStringInMixedUnion] |
2192 | | -from typing import Literal, Tuple |
2193 | | -typ: Tuple[Literal['a', 'b'], ...] = ('a', 'b') |
2194 | | -x: str = "hi!" |
2195 | | -if x in typ: |
2196 | | - reveal_type(x) # N: Revealed type is "Union[Literal['a'], Literal['b']]" |
2197 | | -else: |
2198 | | - reveal_type(x) # N: Revealed type is "builtins.str" |
2199 | | -[builtins fixtures/tuple.pyi] |
2200 | | -[typing fixtures/typing-medium.pyi] |
2201 | | - |
2202 | | -[case testTypeNarrowingStringInSet] |
2203 | | -from typing import Literal, Set |
2204 | | -typ: Set[Literal['a', 'b']] = {'a', 'b'} |
2205 | | -x: str = "hi!" |
2206 | | -if x in typ: |
2207 | | - reveal_type(x) # N: Revealed type is "Union[Literal['a'], Literal['b']]" |
2208 | | -else: |
2209 | | - reveal_type(x) # N: Revealed type is "builtins.str" |
2210 | | -if x not in typ: |
2211 | | - reveal_type(x) # N: Revealed type is "builtins.str" |
2212 | | -else: |
2213 | | - reveal_type(x) # N: Revealed type is "Union[Literal['a'], Literal['b']]" |
2214 | | -[builtins fixtures/narrowing.pyi] |
2215 | | -[typing fixtures/typing-medium.pyi] |
2216 | | - |
2217 | | -[case testTypeNarrowingStringInList] |
2218 | | -from typing import Literal, List |
2219 | | -typ: List[Literal['a', 'b']] = ['a', 'b'] |
2220 | | -x: str = "hi!" |
2221 | | -if x in typ: |
2222 | | - reveal_type(x) # N: Revealed type is "Union[Literal['a'], Literal['b']]" |
2223 | | -else: |
2224 | | - reveal_type(x) # N: Revealed type is "builtins.str" |
2225 | | -if x not in typ: |
2226 | | - reveal_type(x) # N: Revealed type is "builtins.str" |
2227 | | -else: |
2228 | | - reveal_type(x) # N: Revealed type is "Union[Literal['a'], Literal['b']]" |
2229 | | -[builtins fixtures/narrowing.pyi] |
2230 | | -[typing fixtures/typing-medium.pyi] |
2231 | | - |
2232 | | -[case testTypeNarrowingUnionStringFloat] |
2233 | | -from typing import Union |
2234 | | -def foobar(foo: Union[str, float]): |
2235 | | - if foo in ['a', 'b']: |
2236 | | - reveal_type(foo) # N: Revealed type is "builtins.str" |
2237 | | - else: |
2238 | | - reveal_type(foo) # N: Revealed type is "Union[builtins.str, builtins.float]" |
2239 | | -[builtins fixtures/primitives.pyi] |
2240 | | -[typing fixtures/typing-medium.pyi] |