Skip to content

Commit 879b274

Browse files
committed
60% of tests
1 parent 18642d0 commit 879b274

File tree

4 files changed

+97
-62
lines changed

4 files changed

+97
-62
lines changed

test-data/unit/check-typeis.test

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ accept_typeguard(typeguard)
819819
[builtins fixtures/tuple.pyi]
820820

821821
[case testTypeIsInOverloads]
822+
# flags: --warn-unreachable
822823
from typing import Any, overload, Union
823824
from typing_extensions import TypeIs
824825

@@ -843,13 +844,15 @@ def func3(val: Union[int, str]):
843844
if func1(val):
844845
reveal_type(val) # N: Revealed type is "Union[builtins.int, builtins.str]"
845846
else:
846-
reveal_type(val)
847+
reveal_type(val) # E: Statement is unreachable \
848+
# N: Revealed type is "Union[builtins.int, builtins.str]"
847849

848850
def func4(val: int):
849851
if func1(val):
850852
reveal_type(val) # N: Revealed type is "builtins.int"
851853
else:
852-
reveal_type(val)
854+
reveal_type(val) # E: Statement is unreachable \
855+
# N: Revealed type is "builtins.int"
853856
[builtins fixtures/tuple.pyi]
854857

855858
[case testTypeIsInOverloadsSameReturn]

test-data/unit/check-typevar-tuple.test

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,15 +1273,17 @@ def test(d: A[int, str]) -> None:
12731273
if isinstance(d, A):
12741274
reveal_type(d) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.A[builtins.int, builtins.str]]"
12751275
else:
1276-
reveal_type(d) # E: Statement is unreachable
1276+
reveal_type(d) # E: Statement is unreachable \
1277+
# N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.A[builtins.int, builtins.str]]"
12771278

12781279
class B(Generic[Unpack[TP]]): ...
12791280

12801281
def test2(d: B[int, str]) -> None:
12811282
if isinstance(d, B):
12821283
reveal_type(d) # N: Revealed type is "__main__.B[builtins.int, builtins.str]"
12831284
else:
1284-
reveal_type(d) # E: Statement is unreachable
1285+
reveal_type(d) # E: Statement is unreachable \
1286+
# N: Revealed type is "__main__.B[builtins.int, builtins.str]"
12851287
[builtins fixtures/isinstancelist.pyi]
12861288

12871289
[case testVariadicTupleSubtyping]

test-data/unit/check-typevar-values.test

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -112,35 +112,33 @@ from typing import TypeVar
112112
T = TypeVar('T', int, str)
113113
def f(x: T) -> T:
114114
if isinstance(x, int):
115-
return 2
115+
return 2 # E: Incompatible return value type (got "int", expected "str")
116116
return x
117117
def g(x: T) -> T:
118118
if isinstance(x, str):
119-
return ''
119+
return '' # E: Incompatible return value type (got "str", expected "int")
120120
return x
121121
def h(x: T) -> T:
122122
if isinstance(x, int):
123123
return '' # E: Incompatible return value type (got "str", expected "int")
124124
return x
125125
[builtins fixtures/isinstance.pyi]
126-
[out]
127126

128127
[case testIsinstanceAndTypeVarValues2]
129128
from typing import TypeVar
130129
T = TypeVar('T', int, str)
131130
def f(x: T) -> T:
132131
if isinstance(x, int):
133-
return 2
132+
return 2 # E: Incompatible return value type (got "int", expected "str")
134133
else:
135-
return ''
134+
return '' # E: Incompatible return value type (got "str", expected "int")
136135
def g(x: T) -> T:
137136
if isinstance(x, int):
138137
return '' # E: Incompatible return value type (got "str", expected "int")
139138
else:
140139
return 2 # E: Incompatible return value type (got "int", expected "str")
141140
return x
142141
[builtins fixtures/isinstance.pyi]
143-
[out]
144142

145143
[case testIsinstanceAndTypeVarValues3]
146144
from typing import TypeVar
@@ -149,8 +147,8 @@ def f(x: T) -> T:
149147
if isinstance(x, int):
150148
y = 1
151149
else:
152-
y = ''
153-
return y
150+
y = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int")
151+
return y # E: Incompatible return value type (got "int", expected "str")
154152
[builtins fixtures/isinstance.pyi]
155153

156154
[case testIsinstanceAndTypeVarValues4]
@@ -160,10 +158,9 @@ def f(x: T) -> T:
160158
if isinstance(x, int):
161159
y = 1
162160
else:
163-
y = object()
164-
return y # E: Incompatible return value type (got "object", expected "str")
161+
y = object() # E: Incompatible types in assignment (expression has type "object", variable has type "int")
162+
return y # E: Incompatible return value type (got "int", expected "str")
165163
[builtins fixtures/isinstance.pyi]
166-
[out]
167164

168165
[case testIsinstanceAndTypeVarValues5]
169166
from typing import TypeVar
@@ -189,9 +186,10 @@ def f1(x: T1) -> None:
189186
x = y
190187
x = A() # E: Incompatible types in assignment (expression has type "A", variable has type "B")
191188
else:
192-
x = B()
189+
x = B() # E: Incompatible types in assignment (expression has type "B", variable has type "A")
193190
x = y
194-
x.foo() # E: "B" has no attribute "foo"
191+
x.foo() # E: "A" has no attribute "foo" \
192+
# E: "B" has no attribute "foo"
195193

196194
class C:
197195
field: int
@@ -203,19 +201,19 @@ def f2(x: T2) -> None:
203201
if isinstance(x, C):
204202
# C and D are non-overlapping, so this branch is never checked
205203
x = y
206-
x = C()
204+
x = C() # E: Incompatible types in assignment (expression has type "C", variable has type "D")
207205
else:
208-
x = D()
206+
x = D() # E: Incompatible types in assignment (expression has type "D", variable has type "C")
209207
x = y
210-
x.foo() # E: "D" has no attribute "foo"
208+
x.foo() # E: "C" has no attribute "foo" \
209+
# E: "D" has no attribute "foo"
211210

212211
S = TypeVar('S', int, str)
213212
def g(x: S) -> None:
214213
y = x
215214
if isinstance(x, int):
216215
x = y
217216
[builtins fixtures/isinstance.pyi]
218-
[out]
219217

220218
[case testIsinstanceWithUserDefinedTypeAndTypeVarValues2]
221219
from typing import TypeVar
@@ -226,14 +224,13 @@ def f(x: T) -> None:
226224
if isinstance(x, S):
227225
# This is checked only when type of x is str.
228226
x = y
229-
x = S()
227+
x = S() # E: Incompatible types in assignment (expression has type "S", variable has type "int")
230228
x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "S")
231229
else:
232230
x = y
233-
x = 1
231+
x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "S")
234232
x = S() # E: Incompatible types in assignment (expression has type "S", variable has type "int")
235233
[builtins fixtures/isinstance.pyi]
236-
[out]
237234

238235
[case testTypeVarValuesAndNestedCalls]
239236
from typing import TypeVar
@@ -740,8 +737,10 @@ W = TypeVar("W", int, str)
740737

741738
def fn(w: W) -> W:
742739
if type(w) is str:
743-
reveal_type(w) # N: Revealed type is "builtins.str"
740+
reveal_type(w) # N: Revealed type is "builtins.int" \
741+
# N: Revealed type is "builtins.str"
744742
elif type(w) is int:
745-
reveal_type(w) # N: Revealed type is "builtins.int"
743+
reveal_type(w) # N: Revealed type is "builtins.int" \
744+
# N: Revealed type is "builtins.str"
746745
return w
747746
[builtins fixtures/isinstance.pyi]

0 commit comments

Comments
 (0)