Skip to content

Commit 87ec940

Browse files
yangdanny97facebook-github-bot
authored andcommitted
fix bug w/ kwonly parameter & notrequired typeddict item
Summary: Handle a case that gave a weird error in python/typing#1918 Keyword only parameters were always treated as not having defaults, which made them incompatible with notrequired typeddict items. Reviewed By: rchen152 Differential Revision: D69222079 fbshipit-source-id: 5f4ac60d5bc3f7fa5da4b3709f0364f21f8d94aa
1 parent 1a5e6f2 commit 87ec940

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

source/analysis/signatureSelection.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,7 @@ let check_arguments_against_parameters
11571157
let has_default =
11581158
match parameter with
11591159
| Named { default; _ } -> default
1160+
| KeywordOnly { default; _ } -> default
11601161
| _ -> false
11611162
in
11621163
let rec check ~arguments signature_match =

source/analysis/test/integration/typedDictionaryTest.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,6 +2584,19 @@ class Movie(TypedDict, total=False):
25842584
def foo(name: str = "") -> None:
25852585
pass
25862586
kwargs: Movie = {"name": "Life of Brian"}
2587+
foo(**kwargs)
2588+
|}
2589+
[];
2590+
labeled_test_case __FUNCTION__ __LINE__
2591+
@@ assert_type_errors_inject_typing_and_typing_extensions
2592+
{|
2593+
from typing import TypedDict
2594+
from typing_extensions import Unpack
2595+
class Movie(TypedDict, total=False):
2596+
name: str
2597+
def foo(*, name: str = "") -> None:
2598+
pass
2599+
kwargs: Movie = {"name": "Life of Brian"}
25872600
foo(**kwargs)
25882601
|}
25892602
[];

0 commit comments

Comments
 (0)