Skip to content

Commit 07d64f5

Browse files
committed
Add test case
Fix #1914.
1 parent dc62a99 commit 07d64f5

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎test-data/unit/check-unions.test‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,18 @@ from typing import Union
280280
class A: pass
281281
def f(x: Union[int, str, A]):
282282
x + object() # E: Unsupported left operand type for + (some union)
283+
284+
[case testNarrowingDownNamedTupleUnion]
285+
from typing import NamedTuple, Union
286+
287+
A = NamedTuple('A', [('y', int)])
288+
B = NamedTuple('B', [('x', int)])
289+
C = NamedTuple('C', [('x', int)])
290+
291+
def foo(a: Union[A, B, C]):
292+
if isinstance(a, (B, C)):
293+
reveal_type(a) # E: Revealed type is 'Union[Tuple[builtins.int, fallback=__main__.B], Tuple[builtins.int, fallback=__main__.C]]'
294+
a.x
295+
a.y # E: Some element of union has no attribute "y"
296+
b = a # type: Union[B, C]
297+
[builtins fixtures/isinstance.pyi]

0 commit comments

Comments
 (0)