-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Infer precise signatures for TypedDict types
- Loading branch information
1 parent
2cad48c
commit f1e2794
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# static analysis: ignore | ||
from .implementation import assert_is_value | ||
from .value import SubclassValue, TypedDictValue, TypedValue | ||
from .test_name_check_visitor import TestNameCheckVisitorBase | ||
from .test_node_visitor import assert_passes | ||
|
||
|
||
class TestTypedDict(TestNameCheckVisitorBase): | ||
@assert_passes() | ||
def test_constructor(self): | ||
from typing_extensions import TypedDict, NotRequired | ||
|
||
class Capybara(TypedDict): | ||
x: int | ||
y: str | ||
|
||
class MaybeCapybara(TypedDict): | ||
x: int | ||
y: NotRequired[str] | ||
|
||
def capybara(): | ||
cap = Capybara(x=1, y="2") | ||
assert_is_value( | ||
cap, | ||
TypedDictValue( | ||
{"x": (True, TypedValue(int)), "y": (True, TypedValue(str))} | ||
), | ||
) | ||
Capybara(x=1) # E: incompatible_call | ||
|
||
maybe_cap = MaybeCapybara(x=1) | ||
assert_is_value( | ||
maybe_cap, | ||
TypedDictValue( | ||
{"x": (True, TypedValue(int)), "y": (False, TypedValue(str))} | ||
), | ||
) |