Skip to content

Commit 88e2c9f

Browse files
committed
add testOperatorContainsNarrowsTypedDicts_unionWithList
1 parent e67c6f8 commit 88e2c9f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test-data/unit/check-typeddict.test

+21
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,27 @@ v = {bad2: 2} # E: Extra key "bad" for TypedDict "Value"
20122012
[builtins fixtures/dict.pyi]
20132013
[typing fixtures/typing-typeddict.pyi]
20142014

2015+
[case testOperatorContainsNarrowsTypedDicts_unionWithList]
2016+
from __future__ import annotations
2017+
from typing import assert_type, TypedDict, Union
2018+
from typing_extensions import final
2019+
2020+
2021+
@final
2022+
class D(TypedDict):
2023+
foo: int
2024+
2025+
2026+
d: D | list[str]
2027+
2028+
if 'foo' in d:
2029+
assert_type(d, Union[D, list[str]])
2030+
else:
2031+
assert_type(d, list[str])
2032+
2033+
[builtins fixtures / dict.pyi]
2034+
[typing fixtures / typing - typeddict.pyi]
2035+
20152036
[case testOperatorContainsNarrowsTotalTypedDicts]
20162037
from __future__ import annotations
20172038
from typing import assert_type, Literal, TypedDict, TypeVar, Union

0 commit comments

Comments
 (0)