-
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.
Added experimental support for draft PEP 764: Inlined typed dictionar…
…ies. (#9350)
- Loading branch information
Showing
6 changed files
with
144 additions
and
12 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
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
40 changes: 40 additions & 0 deletions
40
packages/pyright-internal/src/tests/samples/typedDictInline1.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,40 @@ | ||
# This sample tests support for inlined TypedDict definitions. | ||
|
||
from typing import NotRequired, ReadOnly, Required, TypedDict | ||
|
||
|
||
td1: TypedDict[{"a": int, "b": str}] = {"a": 0, "b": ""} | ||
|
||
td2: TypedDict[{"a": TypedDict[{"b": int}]}] = {"a": {"b": 0}} | ||
|
||
td3: TypedDict[{"a": "list[float]"}] = {"a": [3]} | ||
|
||
td4: TypedDict[ | ||
{"a": NotRequired[int], "b": Required[int], "c": NotRequired[ReadOnly[int]]} | ||
] = {"b": 3} | ||
|
||
# This should generate an error because dictionary comprehensions | ||
# are not allowed. | ||
err1: TypedDict[{"a": int for _ in range(1)}] | ||
|
||
# This should generate an error because unpacked dictionary | ||
# entries are not allowed. | ||
err2: TypedDict[{**{"a": int}}] | ||
|
||
# This should generate an error because an extra type argument is provided. | ||
err3: TypedDict[{"a": int}, str] | ||
|
||
# This should generate an error because TypedDict cannot be used without | ||
# a subscript in this context. | ||
err4: TypedDict | ||
|
||
# This should generate an error because a dict expression is not a | ||
# valid type expression by itself. | ||
err5: TypedDict[{"a": {"b": int}}] = {"a": {"b": 0}} | ||
|
||
|
||
def func1(val: TypedDict[{"a": int}]) -> TypedDict[{"a": int}]: | ||
return {"a": val["a"] + 1} | ||
|
||
|
||
func1({"a": 3}) |
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