Skip to content

Commit b0b7627

Browse files
committed
Add a challenge for Unpack, closed #58
1 parent d6bd3a1 commit b0b7627

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Finish typed-dict challenges first
2+
- Check out [Unpack](https://docs.python.org/3/library/typing.html#typing.Unpack)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
TODO:
3+
4+
`foo` expects two keyword arguments - `name` of type `str`, and `age` of type `int`.
5+
"""
6+
7+
from typing import TypedDict
8+
9+
10+
class Person(TypedDict):
11+
name: str
12+
age: int
13+
14+
15+
def foo(**kwargs):
16+
...
17+
18+
19+
## End of your code ##
20+
person: Person = {"name": "The Meaning of Life", "age": 1983}
21+
foo(**person)
22+
foo(**{"name": "Brian", "age": 30})
23+
24+
foo(**{"name": "Brian"}) # expect-type-error
25+
person2: dict[str, object] = {"name": "Brian", "age": 20}
26+
foo(**person2) # expect-type-error
27+
foo(**{"name": "Brian", "age": "1979"}) # expect-type-error
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
TODO:
3+
4+
`foo` expects two keyword arguments - `name` of type `str`, and `age` of type `int`.
5+
"""
6+
7+
from typing import Unpack, TypedDict
8+
9+
10+
class Person(TypedDict):
11+
name: str
12+
age: int
13+
14+
15+
def foo(**kwargs: Unpack[Person]):
16+
...
17+
18+
19+
## End of your code ##
20+
person: Person = {"name": "The Meaning of Life", "age": 1983}
21+
foo(**person)
22+
foo(**{"name": "Brian", "age": 30})
23+
24+
foo(**{"name": "Brian"}) # expect-type-error
25+
person2: dict[str, object] = {"name": "Brian", "age": 20}
26+
foo(**person2) # expect-type-error
27+
foo(**{"name": "Brian", "age": "1979"}) # expect-type-error

0 commit comments

Comments
 (0)