Skip to content

Commit

Permalink
test totality through both total= and (Not)Required
Browse files Browse the repository at this point in the history
  • Loading branch information
ikonst committed Oct 19, 2022
1 parent f72a634 commit bf4364f
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion test-data/unit/check-typeddict.test
Original file line number Diff line number Diff line change
Expand Up @@ -2124,7 +2124,7 @@ else:
[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]

[case testOperatorContainsNarrowsTypedDicts_partial]
[case testOperatorContainsNarrowsTypedDicts_partialThroughTotalFalse]
from __future__ import annotations
from typing import assert_type, Literal, TypedDict, Union
from typing_extensions import final
Expand Down Expand Up @@ -2160,6 +2160,38 @@ else:
[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]

[case testOperatorContainsNarrowsTypedDicts_partialThroughNotRequired]
from __future__ import annotations
from typing import assert_type, Required, NotRequired, TypedDict, Union
from typing_extensions import final

@final
class D1(TypedDict):
required_key: Required[int]
optional_key: NotRequired[int]


@final
class D2(TypedDict):
abc: int
xyz: int


d: D1 | D2

if 'required_key' in d:
assert_type(d, D1)
else:
assert_type(d, D2)

if 'optional_key' in d:
assert_type(d, D1)
else:
assert_type(d, Union[D1, D2])

[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]

[case testCannotSubclassFinalTypedDict]
from typing import TypedDict
from typing_extensions import final
Expand Down

0 comments on commit bf4364f

Please sign in to comment.