-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathquestion.py
More file actions
45 lines (29 loc) · 844 Bytes
/
question.py
File metadata and controls
45 lines (29 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
TODO:
Define an "tupled" function that accepts a function and returns a function with some arguments in the form of a tuple.
The return type should remain unchanged.
(if you're familiar with scala, this is effectively the "tupled" function)
"""
def tupled(func):
def impl(args):
return func(*args)
return impl
## End of your code ##
from typing import Any
def func0() -> Any:
...
def func1(s: str) -> Any:
...
def func2(s: str, i: int) -> Any:
...
func0_tupled = tupled(func0)
func0_tupled(())
func0_tupled() # expect-type-error
func1_tupled = tupled(func1)
func1_tupled(("a",))
func1_tupled("a") # expect-type-error
func1_tupled(1) # expect-type-error
func2_tupled = tupled(func2)
func2_tupled(("a", 1))
func2_tupled(("a", "b")) # expect-type-error
func2_tupled("a", 1) # expect-type-error