Skip to content

Commit

Permalink
update tests per hauntsaninja's code review
Browse files Browse the repository at this point in the history
  • Loading branch information
ikonst committed Nov 3, 2022
1 parent 062fcb1 commit 520df60
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions test-data/unit/check-typeddict.test
Original file line number Diff line number Diff line change
Expand Up @@ -2022,12 +2022,14 @@ class D(TypedDict):
foo: int


d: D | list[str]
d_or_list: D | list[str]

if 'foo' in d:
assert_type(d, Union[D, list[str]])
if 'foo' in d_or_list:
assert_type(d_or_list, Union[D, list[str]])
elif 'bar' in d_or_list:
assert_type(d_or_list, list[str])
else:
assert_type(d, list[str])
assert_type(d_or_list, list[str])

[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]
Expand All @@ -2046,12 +2048,6 @@ class D1(TypedDict):
class D2(TypedDict):
bar: int

d_or_list: D1 | list[str]

if 'foo' in d_or_list:
assert_type(d_or_list, Union[D1, list[str]])
else:
assert_type(d_or_list, list[str])

d: D1 | D2

Expand All @@ -2077,11 +2073,9 @@ TD = TypeVar('TD', D1, D2)
def f(arg: TD) -> None:
value: int
if 'foo' in arg:
assert_type(d, Union[D1, D2]) # strangely enough it's seen as a union
value = arg['foo'] # but acts here as D1
assert_type(arg['foo'], int)
else:
assert_type(d, Union[D1, D2]) # ditto here, but D2
value = arg['bar']
assert_type(arg['bar'], int)


[builtins fixtures/dict.pyi]
Expand Down

0 comments on commit 520df60

Please sign in to comment.