File tree Expand file tree Collapse file tree 3 files changed +56
-0
lines changed
challenges/intermediate-unpack Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ - Finish typed-dict challenges first
2
+ - Check out [ Unpack] ( https://docs.python.org/3/library/typing.html#typing.Unpack )
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments