Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test case
Fix #1914.
  • Loading branch information
JukkaL committed Mar 20, 2017
commit 07d64f5c9cb98e89754bd5e5104e76fd71c280f3
15 changes: 15 additions & 0 deletions test-data/unit/check-unions.test
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,18 @@ from typing import Union
class A: pass
def f(x: Union[int, str, A]):
x + object() # E: Unsupported left operand type for + (some union)

[case testNarrowingDownNamedTupleUnion]
from typing import NamedTuple, Union

A = NamedTuple('A', [('y', int)])
B = NamedTuple('B', [('x', int)])
C = NamedTuple('C', [('x', int)])

def foo(a: Union[A, B, C]):
if isinstance(a, (B, C)):
reveal_type(a) # E: Revealed type is 'Union[Tuple[builtins.int, fallback=__main__.B], Tuple[builtins.int, fallback=__main__.C]]'
a.x
a.y # E: Some element of union has no attribute "y"
b = a # type: Union[B, C]
[builtins fixtures/isinstance.pyi]