-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed the behavior of the dictionary expansion operator (
**
) when…
… used in an argument expression for a call and the operand is a TypedDict. It now takes into account the fact that a (non-closed) TypedDict can contain additional keys with `object` values. This new behavior is consistent with mypy. This addresses #8894. (#8908)
- Loading branch information
Showing
5 changed files
with
90 additions
and
11 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
38 changes: 38 additions & 0 deletions
38
packages/pyright-internal/src/tests/samples/typedDictClosed9.py
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,38 @@ | ||
# This sample tests the handling of calls with unpacked TypedDicts. | ||
|
||
|
||
from typing_extensions import TypedDict # pyright: ignore[reportMissingModuleSource] | ||
|
||
|
||
class ClosedTD1(TypedDict, closed=True): | ||
arg1: str | ||
|
||
|
||
class IntDict1(TypedDict, closed=True): | ||
arg1: str | ||
__extra_items__: int | ||
|
||
|
||
td1 = ClosedTD1(arg1="hello") | ||
td2 = IntDict1(arg1="hello", arg2=3) | ||
|
||
|
||
def func1(arg1: str): | ||
pass | ||
|
||
|
||
func1(**td1) | ||
|
||
# This should arguably generate an error because there | ||
# could be extra items, but we'll match mypy's behavior here. | ||
func1(**td2) | ||
|
||
|
||
def func2(arg1: str, **kwargs: str): | ||
pass | ||
|
||
|
||
func2(**td1) | ||
|
||
# This should result in an error. | ||
func2(**td2) |
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